Skip to content

Build the wasm module with -DNDEBUG - #3066

Merged
soutaro merged 1 commit into
masterfrom
claude/wasm-ndebug-build-ytf7tz
Aug 3, 2026
Merged

Build the wasm module with -DNDEBUG#3066
soutaro merged 1 commit into
masterfrom
claude/wasm-ndebug-build-ytf7tz

Conversation

@soutaro

@soutaro soutaro commented Aug 3, 2026

Copy link
Copy Markdown
Member

rake wasm:build was compiling the parser without NDEBUG, so every RBS_ASSERT survived into rbs_parser.wasm — unlike the MRI extension, which already drops them in ext/rbs_extension/extconf.rb.

It was up to 20% slower with RBS_ASSERT calls.

This adds -DNDEBUG to the wasm build, with DEBUG=1 rake wasm:build as the escape hatch for keeping the assertions, matching the DEBUG convention extconf.rb and the prepare_bench / prepare_profiling tasks already use.

Measurements

Parsing core/ + stdlib/ (250 files, 4.3MB), best of 10, three rounds:

assert build -DNDEBUG
parse, V8 (Node WASI) 75.7 / 75.9 / 77.3 ms 61.9 / 62.6 / 62.8 ms -18%
parse, wasmtime 74.4 / 75.4 / 76.5 ms 59.5 / 61.0 / 62.3 ms -20%
lex only, wasmtime 65.6 ms 60.9 ms -7%

`rake wasm:build` compiled the parser without `NDEBUG`, so every `RBS_ASSERT`
survived into `rbs_parser.wasm`. The MRI extension already drops them
(ext/rbs_extension/extconf.rb), and the assertions that matter sit on the
hottest paths there are: two per character in `rbs_encoding.c`, one per
character in `rbs_skip`, and five around the constant pool. Each one is an
out-of-line varargs call to `rbs_assert_impl`, which the compiler cannot inline
away, so the cost is paid on every character lexed.

Parsing core/ + stdlib/ (250 files, 4.3MB) through a WASI host, best of 10:

    assert build  75.7 ms
    NDEBUG build  61.9 ms   (-18%)

Measured the same on wasmtime and on V8. The serialized ASTs for all 250 files
are byte-identical between the two builds.

`DEBUG=1 rake wasm:build` keeps the assertions, matching the DEBUG convention
extconf.rb and the prepare_bench / prepare_profiling tasks already use.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012uu4EqN6azBeVjM9F71TUp
@soutaro
soutaro enabled auto-merge August 3, 2026 14:53
@soutaro
soutaro added this pull request to the merge queue Aug 3, 2026
Merged via the queue into master with commit 4752d54 Aug 3, 2026
25 checks passed
@soutaro
soutaro deleted the claude/wasm-ndebug-build-ytf7tz branch August 3, 2026 15:00
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