emscripten-core / emscripten-core/emscripten

Proposal: __deps: ["$Foo.bar"] for individual properties on objects

Open
#20,022 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

Example of the hypothetical usage:
```js
foo__deps: ['$FS.cwd'],
foo: function(file) {
work(file, FS.cwd());
},
```
Rather than `$FS` in the above, we depend on `$FS.cwd` specifically.

The goal here is avoid including an entire huge object all the time. We have such large objects in `FS` and `Browser`, for example, and using even a single property forces the entire thing to be added, which this proposal could avoid.

Specifically I found the need for this in WasmFS. WasmFS has much less code in JS than the original FS, but there are many JS APIs that call `FS.*` APIs, and right now that is very cumbersome. One option has been to rewrite JS code in wasm to avoid JS deps, and I tried that for `emscripten_async_wget` [in a branch](https://github.com/emscripten-core/emscripten/compare/wasmfs.async_wget?expand=1), but it turns out to be much less pleasant to write that code in C or C++ than JS (simply because JS has such nice ergonomics for async).

This should not cause any breaking changes. It would only influence new code that uses such deps. Implementation-wise, the deps system would special case a dep of a string `X.Y`. That already can't be the name of a JS object, so such deps have never existed, unless I'm missing something.

This would take a little work in jsifier, since we'd only be able to emit an object X after knowing all properties that it uses. But I hope that won't be too bad.

I would use this for WasmFS initially, but we could also apply it to `Browser` and other things and potentially get some nice code size wins.

Thoughts? Alternatives?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.