Stream: StarlingMonkey

Topic: Continuous memory growth in jco component


view this post on Zulip Ludvig Liljenberg (Jul 31 2025 at 23:33):

Hello I have a very simple question about jco components. I have a simple wasm component compiled from the following js

export const handlerInterface = {
    handleevent(event) {
        return event;
    }
};

using jco componentize handler.js --wit ../component.wit -d all -o handler.wasm
with the following wit

package test:test;

interface handler-interface {
    record request {
        uri: string
    }

    handleevent: func(event: request) -> request;
}

world handler-world {
    export handler-interface;
}

I'm using wasmtime to call the handleevent guest function on the component in an infinite loop. It seems that RES memory of the process is constantly increasing over time. Is this expected with components compiled with jco? I don't see the same memory usage using cargo-component for example. Maybe it's expected with a javascript runtime and JIT or whatnot, but it would seem weird to me? Any help appreciated.

Small repro is here https://github.com/ludfjig/jco-vs-cargo-component-memory-usage

Compares memory usage of jco vs cargo-component. Contribute to ludfjig/jco-vs-cargo-component-memory-usage development by creating an account on GitHub.

view this post on Zulip Tomasz Andrzejak (Aug 01 2025 at 06:11):

Hey Ludvig, thank you for the repro. No, this is not expected behavior. Unfortunately, StarlingMonkey hasn't been thoroughly tested for long-running use cases, so it's entirely possible that we have a memory leak somewhere. I would start by ensuring you're using the latest jco version, as there were some memory-related fixes in the most recent StarlingMonkey release, and I will have a look at your example to see if I'm able to track the leak.

view this post on Zulip Tomasz Andrzejak (Aug 01 2025 at 07:03):

To provide additional context: I would also say it's normal to see memory usage fluctuations in JS components due to garbage collection. The GC will allow memory to accumulate temporarily before triggering a collection that should eventually bring memory usage down, but FWIU what you're observing is linear increase until oom?

view this post on Zulip Ludvig Liljenberg (Aug 01 2025 at 17:17):

Thanks for the reply. Indeed memory increases linearly with no signs of stabilizing. I tried most recent jco version as well, but unfortunately I'm still seeing it

view this post on Zulip Victor Adossi (Aug 04 2025 at 09:36):

Hey @Ludvig Liljenberg would you mind filing an issue about this? The most appropriate place might be either componentize-js or StarlingMonkey , but I'd love to track this so that we can be sure it's fixed long-term.

I mention this because I originally thought this might be a case of this bug from Jco, but it doesn't seem to be, so I'm thinking we should make sure it's tracked.

Hey all, thanks for the cool project! I've been following various talks in the space for the last year and am really excited to be trying out some stuff! Background I'm working in a Rust codebase t...

view this post on Zulip Notification Bot (Aug 05 2025 at 20:12):

This topic was moved here from #general > Continuous memory growth in jco component by fitzgen (he/him).

view this post on Zulip Ludvig Liljenberg (Aug 07 2025 at 18:39):

Thanks, I filed https://github.com/bytecodealliance/ComponentizeJS/issues/279

I have a simple wasm component compiled from the following js export const handlerInterface = { handleevent(event) { return event; } }; using jco componentize handler.js --wit ../component.wit -d a...

view this post on Zulip Ludvig Liljenberg (Sep 16 2025 at 00:10):

I think I found the issue! I've made a PR here https://github.com/bytecodealliance/ComponentizeJS/pull/295 @Victor Adossi @Tomasz Andrzejak

JavaScript components leak memory when returning non-primitive types (strings, objects, arrays, etc.). Cause Return pointer allocation used JS_realloc which bypasses memory tracking, so allocations...

view this post on Zulip Victor Adossi (Sep 16 2025 at 10:02):

Great job @Ludvig Liljenberg !


Last updated: Dec 06 2025 at 06:05 UTC