Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory leak in "resize" module caused by wee_alloc #53

Merged
merged 8 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/resize/.npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
node_modules
*.d.ts.map
tsconfig.tsbuildinfo
src
target
*.rs
cargo.toml
Cargo.lock
pkg/package.json
12 changes: 12 additions & 0 deletions packages/resize/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

## @jsquash/resize@2.0.0

### Breaking Changes

- Moves compiled wasm and js files to the 'lib/*/pkg' directory. If you were using the wasm file directly you will need to update your paths to reference the following
- `node_modules/@jsquash/resize/lib/hqx/pkg/squooshhqx_bg.wasm`
- `node_modules/@jsquash/resize/lib/resize/pkg/squoosh_resize_bg.wasm`

### Fixes

- Fixes memory leak caused by a bug with wee_alloc

## @jsquash/resize@1.1.1

### Fixes
Expand Down
8 changes: 4 additions & 4 deletions packages/resize/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { WorkerResizeOptions } from './meta.js';
import type { InitInput as InitResizeInput } from './lib/resize/squoosh_resize.js';
import type { InitInput as InitHqxInput } from './lib/hqx/squooshhqx.js';
import type { InitInput as InitResizeInput } from './lib/resize/pkg/squoosh_resize.js';
import type { InitInput as InitHqxInput } from './lib/hqx/pkg/squooshhqx.js';
import { getContainOffsets } from './util.js';
import initResizeWasm, {
resize as wasmResize,
} from './lib/resize/squoosh_resize.js';
import initHqxWasm, { resize as wasmHqx } from './lib/hqx/squooshhqx.js';
} from './lib/resize/pkg/squoosh_resize.js';
import initHqxWasm, { resize as wasmHqx } from './lib/hqx/pkg/squooshhqx.js';
import { defaultOptions } from './meta.js';

let resizeWasmReady: Promise<unknown>;
Expand Down
250 changes: 250 additions & 0 deletions packages/resize/lib/hqx/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions packages/resize/lib/hqx/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[package]
name = "squooshhqx"
version = "0.1.0"
authors = ["Surma <surma@surma.link>"]

[lib]
crate-type = ["cdylib"]

[features]
default = ["console_error_panic_hook"]

[dependencies]
cfg-if = "0.1.2"
wasm-bindgen = "0.2.38"
# lazy_static = "1.0.0"
hqx = {git = "https://github.com/CryZe/wasmboy-rs", tag="v0.1.3"}

# The `console_error_panic_hook` crate provides better debugging of panics by
# logging them with `console.error`. This is great for development, but requires
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
# code size when deploying.
console_error_panic_hook = { version = "0.1.1", optional = true }

[dev-dependencies]
wasm-bindgen-test = "0.2"

[profile.release]
# Tell `rustc` to optimize for small code size.
opt-level = "s"
lto = true
16 changes: 4 additions & 12 deletions packages/resize/lib/hqx/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
{
"name": "squooshhqx",
"collaborators": [
"Surma <surma@surma.link>"
],
"version": "0.1.0",
"files": [
"squooshhqx_bg.wasm",
"squooshhqx.js",
"squooshhqx.d.ts"
],
"module": "squooshhqx.js",
"types": "squooshhqx.d.ts",
"sideEffects": false,
"scripts": {
"build": "../../../../tools/build-rust.sh && npm run patch-pre-script",
"patch-pre-script": "cat pre.js >> pkg/squooshhqx.js"
},
"type": "module"
}
5 changes: 5 additions & 0 deletions packages/resize/lib/hqx/pkg/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# HQX

- Source: <https://github.com/CryZe/wasmboy-rs>
- Version: v0.1.2
- License: Apache 2.0
17 changes: 17 additions & 0 deletions packages/resize/lib/hqx/pkg/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "squooshhqx",
"collaborators": [
"Surma <surma@surma.link>"
],
"version": "0.1.0",
"files": [
"squooshhqx_bg.wasm",
"squooshhqx.js",
"squooshhqx.d.ts"
],
"module": "squooshhqx.js",
"types": "squooshhqx.d.ts",
"sideEffects": [
"./snippets/*"
]
}
Loading
Loading