Skip to content

Fix unused and overly-broad __deps entries in JS libraries - #27999

Merged
sbc100 merged 1 commit into
emscripten-core:mainfrom
sbc100:fix_unused_deps
Oct 21, 2026
Merged

sbc100 merged 1 commit into
emscripten-core:mainfrom
sbc100:fix_unused_deps

Conversation

@sbc100

@sbc100 sbc100 commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator
  • In src/lib/libpthread.js, guard '$addOnPreRun' in $PThread__deps
    with #if !MINIMAL_RUNTIME && PTHREAD_POOL_SIZE.
  • Guard or remove other unused and overly-broad __deps entries across
    src/lib/*.js (libasync.js, libbrowser.js, libdylink.js,
    libemval.js, libfetch.js, libfs.js, libglew.js,
    libglut.js, libhtml5.js, libnoderawfs.js, libsdl.js,
    libsockfs_node.js, libwasmfs.js, libwebgl.js, libwebgl2.js).

Split out from #27995

@sbc100
sbc100 requested review from dschuff and kripken October 16, 2026 22:02
@sbc100
sbc100 enabled auto-merge (squash) October 17, 2026 04:13
Comment thread src/lib/libnoderawfs.js
@sbc100
sbc100 force-pushed the fix_unused_deps branch 2 times, most recently from 254d97e to 8911a71 Compare October 20, 2026 00:17
@sbc100

sbc100 commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request optimizes and cleans up library dependencies across various Emscripten JS library files by removing unused dependencies and conditionalizing others under preprocessor flags, resulting in reduced code sizes. The review feedback correctly identifies an issue in src/lib/libglut.js where glutPositionWindow calls Browser.exitFullscreen() but does not declare $Browser in its dependencies, which could lead to a runtime ReferenceError.

Comment thread src/lib/libglut.js Outdated
@sbc100 sbc100 changed the title Fix unused and overly-broad __deps entries in JS libraries. NFC Fix unused and overly-broad __deps entries in JS libraries Oct 20, 2026
@kripken

kripken commented Oct 20, 2026

Copy link
Copy Markdown
Member

This is quite large - any suggestions about how to review it? Ideally we'd have some way to automate the check but nothing comes to mind...

@sbc100

sbc100 commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator Author

I'm sure Gemini could help you review it? You could be sure it say something like "please make sure that you include transitive dependencies in your analysis"?

@sbc100

sbc100 commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator Author

BTW, this change is really just laying ground work for the much bigger change which simply removes all the JS deps.. so it will be very short lives anyway.

@sbc100

sbc100 commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator Author

I you want I could just abandon this cleanup PR and land #27995 directly. The only reason I wanted to land this one first is to try to explain / remove some of the code size saving in #27995.

We could just skip this PR if you prefer though?

@sbc100

sbc100 commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors and optimizes dependency lists across various Emscripten library files by conditionally wrapping them in preprocessor guards or removing unused dependencies, which successfully reduces the compiled code size. The review feedback focuses on improving code readability and maintainability, specifically recommending the use of standard trailing commas instead of fragile leading commas in src/lib/libwebgl.js and wrapping a very long single-line dependency array in src/lib/libhtml5.js onto multiple lines.

Comment thread src/lib/libwebgl.js
Comment thread src/lib/libwebgl.js
Comment thread src/lib/libhtml5.js
@sbc100

sbc100 commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator Author

I split out part of this change: #28034

@kripken

kripken commented Oct 20, 2026

Copy link
Copy Markdown
Member

I you want I could just abandon this cleanup PR and land #27995 directly. The only reason I wanted to land this one first is to try to explain / remove some of the code size saving in #27995.

Does this make reviewing that one any easier? It has 118 changed files and this one has 19, so the benefit can't be large? Maybe I'm not understanding you, sorry.

I'm sure Gemini could help you review it? You could be sure it say something like "please make sure that you include transitive dependencies in your analysis"?

That sounds more like Gemini reviewing it 😄 not Gemini helping me. And I am not confident enough in LLMs to land large changes without further verification.

It doesn't need to be human verification, if we can find an automatic non-LLM method. If we can't, I can do a human review, but it will take a while.

@sbc100

sbc100 commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator Author

I you want I could just abandon this cleanup PR and land #27995 directly. The only reason I wanted to land this one first is to try to explain / remove some of the code size saving in #27995.

Does this make reviewing that one any easier? It has 118 changed files and this one has 19, so the benefit can't be large? Maybe I'm not understanding you, sorry.

Basically its about code size changes. As part of landing #27995 I'm deleting all (most) of the deps entries.

Without first cleaning them all up and making them correct then #27995 also ends up including a bunch of code size reductions.

I'd like to show that #27995 is a no-op. But unless the deps are cleanup up before i lands then it will not be a no-op WRT to codesize.

@sbc100

sbc100 commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator Author

I would like to land this first I think.

The PR is now simpler now that #28034 has landed.

In terms of tools to help you review we do have EMCC_CHECK_DEPS.. but its job is to find unused dependencies, not missing dependencies so it doesn't really help in this case I'm afraid.

@sbc100

sbc100 commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator Author

I can split out, for example, the webgl parts. I'll try that now.

@sbc100

sbc100 commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator Author

webgl changes split out #28037

- In `src/lib/libpthread.js`, guard `'$addOnPreRun'` in `$PThread__deps`
  with `#if !MINIMAL_RUNTIME && PTHREAD_POOL_SIZE`.
- Guard or remove other unused and overly-broad `__deps` entries across
  `src/lib/*.js` (`libasync.js`, `libbrowser.js`, `libdylink.js`,
  `libemval.js`, `libfetch.js`, `libfs.js`, `libglew.js`,
  `libglut.js`, `libhtml5.js`, `libnoderawfs.js`, `libsdl.js`,
  `libsockfs_node.js`, `libwasmfs.js`).

Split out from emscripten-core#27995
@sbc100
sbc100 merged commit 6834051 into emscripten-core:main Oct 21, 2026
42 checks passed
@sbc100
sbc100 deleted the fix_unused_deps branch October 21, 2026 19:55
sbc100 added a commit that referenced this pull request Oct 21, 2026
…es. NFC (#28037)

Align the preprocessor guards on `__deps` arrays with the actual call
sites in the corresponding function bodies so symbols are only pulled in
when referenced:

- In `src/lib/libwebgl.js`:
- Guard `'$webglBufferSubData'` in `$GL__deps` and
`glDrawElements__deps` with `#if FULL_ES2`. In `$GL`,
`webglBufferSubData` is only called from
`preDrawHandleClientVertexAttribBindings` (which is guarded by `#if
FULL_ES2`, not `LEGACY_GL_EMULATION`). Similarly, `glDrawElements` only
calls `webglBufferSubData` inside its `#if FULL_ES2` client-side index
buffer block.
- Guard `'$heapObjectForWebGLType'` and `'$toTypedArrayIndex'` in
`glTexImage2D__deps`, `glTexSubImage2D__deps`, and `glReadPixels__deps`
with `#if WEBGL_USE_GARBAGE_FREE_APIS` instead of `#if MAX_WEBGL_VERSION
>= 2`. Those functions only call `heapObjectForWebGLType` and
`toTypedArrayIndex` directly inside `#if WEBGL_USE_GARBAGE_FREE_APIS`
blocks; otherwise they delegate to `emscriptenWebGLGetTexPixelData`
(which declares its own `__deps`).
- Guard `$webglGetProgramUniformLocation__deps` with `#if
GL_EXPLICIT_UNIFORM_LOCATION`, matching the sole call to
`webglPrepareUniformLocationsBeforeFirstUse` inside
`$webglGetProgramUniformLocation`.
- In `src/lib/libwebgl2.js`:
- Guard `'$toTypedArrayIndex'` in `glTexImage3D__deps` and
`glTexSubImage3D__deps` with `#if WEBGL_USE_GARBAGE_FREE_APIS`, since
`toTypedArrayIndex` is only called in that branch (the `#else` branch
delegates to `emscriptenWebGLGetTexPixelData`).
- Remove `glGetVertexAttribIuiv__deps`. `glGetVertexAttribIuiv` is a
string alias for `'glGetVertexAttribIiv'`, which already declares
`glGetVertexAttribIiv__deps: ['$emscriptenWebGLGetVertexAttrib']`.

Split out from #27999
sbc100 added a commit that referenced this pull request Oct 21, 2026
…FC (#28034)

In `src/lib/libcore.js`, check `t.includes('SYSCALLS.')` instead of
`t.includes('SYSCALLS')` in `wrapSyscallFunction` so comments and
strings mentioning `SYSCALLS_REQUIRE_FILESYSTEM` (such as in `fd_write`)
do not pull in `$SYSCALLS` and `$UTF8ToString` when
`SYSCALLS_REQUIRE_FILESYSTEM=0`.

Split out from #27999
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants