Skip to content

Commit

Permalink
Merge pull request #53 from jamsinclair/fix-resize-memory-leak
Browse files Browse the repository at this point in the history
Fix memory leak in "resize" module caused by wee_alloc
  • Loading branch information
jamsinclair authored Apr 2, 2024
2 parents 5a23825 + cec51d2 commit 1584520
Show file tree
Hide file tree
Showing 34 changed files with 1,121 additions and 98 deletions.
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

0 comments on commit 1584520

Please sign in to comment.