Skip to content

Commit

Permalink
Removed wee-alloc to fix memory leak (#334)
Browse files Browse the repository at this point in the history
I think this closes #305.

rustwasm/wee_alloc#106 is the most likely issue.
  • Loading branch information
simlay committed May 3, 2022
1 parent 993da05 commit 9864fcf
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 57 deletions.
4 changes: 4 additions & 0 deletions .cargo/config
@@ -1,5 +1,9 @@
[build]
target = "wasm32-unknown-unknown"

[target.'cfg(target_arch = "wasm32")']
runner = 'wasm-bindgen-test-runner'


[profile.release]
lto = true
63 changes: 19 additions & 44 deletions Cargo.lock

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

6 changes: 0 additions & 6 deletions Cargo.toml
Expand Up @@ -34,12 +34,6 @@ base64 = "0.13.0"
# code size when deploying.
console_error_panic_hook = { version = "0.1.7" }

# `wee_alloc` is a tiny allocator for wasm that is only ~1K in code size
# compared to the default allocator's ~10K. It is slower than the default
# allocator, however.
#
# Unfortunately, `wee_alloc` requires nightly Rust when targeting wasm for now.
wee_alloc = { version = "0.4.5" }
thiserror = "1.0.31"

[dev-dependencies]
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Expand Up @@ -11,6 +11,8 @@ build-dev:

test: install-wasm-pack
WASM_BINDGEN_TEST_TIMEOUT=30 wasm-pack test --firefox --headless
# Using cargo test with wasm-bindgen-test-runner allows to run specific tests
#NO_HEADLESS=1 GECKODRIVER=$(which geckodriver) cargo test js_tests::simple

build-fluvio-websocket-proxy:
RUST_LOG=debug cargo build --manifest-path ./fluvio-websocket-proxy/Cargo.toml --target $(PROXY_TARGET)
Expand Down
5 changes: 0 additions & 5 deletions src/lib.rs
Expand Up @@ -20,11 +20,6 @@ pub use offset::Offset;
pub use producer::TopicProducer;
pub use record::Record;

// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
// allocator.
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;

use js_sys::Reflect;
use wasm_bindgen::convert::FromWasmAbi;
use wasm_bindgen::JsValue;
Expand Down
5 changes: 3 additions & 2 deletions tests/js/simple/simple.js
Expand Up @@ -2,6 +2,7 @@ import { Offset, Fluvio } from "../../../../../wasm-bindgen-test";
import { createUUID } from "../utils.js";

const topic = createUUID();
const NUMB_RECORDS = 100;

var fluvio;
export const setup = async () => {
Expand Down Expand Up @@ -41,13 +42,13 @@ export const test = async () => {

let count = 0;
const userAgent = navigator.userAgent;
while (count < 100) {
while (count < NUMB_RECORDS) {
count++;
let in_record = `${count}-${userAgent}`;
await producer.send("", in_record);
}
count = 0;
while (count < 100) {
while (count < NUMB_RECORDS) {
count++;
let in_record = `${count}-${userAgent}`;
let next = await stream.next();
Expand Down
2 changes: 2 additions & 0 deletions tests/js_tests.rs
Expand Up @@ -33,12 +33,14 @@ async fn simple() {
.map_err(FluvioError::try_from)
.expect("Setup failed");
web_sys::console::time_end_with_label("simple-setup");
web_sys::console::profile_0();
web_sys::console::time_with_label("simple-test");
test()
.await
.map_err(FluvioError::try_from)
.expect("Test failed");
web_sys::console::time_end_with_label("simple-test");
web_sys::console::profile_end_0();
web_sys::console::time_with_label("simple-teardown");
teardown()
.await
Expand Down

0 comments on commit 9864fcf

Please sign in to comment.