Repository navigation
Remove dead code from the WebSocket client, ncrypto, bun_core, and misc JSC bindings - #40413
Conversation
…sc JSC bindings Rust: the three WebSocket host exports that no C++ caller names (Bun__WebSocketClient__writeBlob, Bun__WebSocketClientTLS__writeBlob, Bun__WebSocketClientTLS__initWithTunnel) and the WebSocketClient::write_blob body behind them, the Bun__internal_drainTimers export, bun_base64::simdutf_encode_url_safe_alloc, bun_core::strings::split_once and rsplit_once, and CowSliceZ::init_unchecked. C++: HTTPParser::lessThan, the HistogramData&& overload of JSNodePerformanceHooksHistogram::create, JSAbortAlgorithm::callbackData and toJS(AbortAlgorithm), JSPerformance::toWrapped, JSCStackFrame::typeName, root(CryptoKey*), the String overload of throwNodeRangeError, and the ncrypto helpers nothing calls (CryptoErrorList::add and pop_front, BignumPointer::encode and encodeInto, X509View::clone, BIOPointer::New(const BIO_METHOD*) and Write, EVPKeyPointer::bits, Cipher::EMPTY, ECKeyPointer::New(const EC_GROUP*), EVPKeyCtxPointer::derive, HMACCtxPointer::digest, and the Ec instance API).
|
Warning Review limit reached
On-demand reviews are free for the next 27 days. After that, they cost $0.25 per reviewed file. Or wait 12 minutes for your next included review. View limit detailsLimit details: You’ve used all 5 included reviews currently available. Review configuration: ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (21)
Comment |
|
Updated 10:48 PM PT - Aug 24th, 2026
✅ @robobun, your commit f3d78cde78b83e982de1fb59e0aa480469c17763 passed in 🧪 To try this PR locally: bunx bun-pr 40413That installs a local version of the PR into your bun-40413 --bun |
There was a problem hiding this comment.
I reviewed this PR and didn't find any bugs. Because it removes ~30 items across 21 files spanning several subsystems (WebSocket client, ncrypto/webcrypto, JSC bindings, timers, bun_core), a human glance would still be worthwhile — mainly to confirm none of the removed ncrypto helpers or the gutted Ec wrapper are wanted for near-term Node-compat work.
What was reviewed:
- Grepped for every removed HOST_EXPORT symbol,
throwNodeRangeError(all callers passASCIILiteral),JSPerformance::toWrapped,root(CryptoKey*),typeName/m_typeName,lessThan,callbackData(),init_unchecked,split_once/rsplit_once,simdutf_encode_url_safe_alloc— no remaining references. - Confirmed
Bun__WebSocketClient__initWithTunnel(non-TLS) is the only tunnel init C++ calls; the TLS variant is unreferenced. - Confirmed the remaining
.getGroup()calls are onECKeyPointer, not the removedEc::getGroup.
Extended reasoning...
Overview
Pure dead-code removal across 21 files: four orphaned Rust HOST_EXPORT thunks (WebSocket writeBlob × 2, TLS initWithTunnel, Bun__internal_drainTimers) plus the write_blob impl; three unused pub Rust items (simdutf_encode_url_safe_alloc, strings::{split_once,rsplit_once}, CowSliceZ::init_unchecked); and a dozen-plus unreferenced C++ methods in ncrypto, ErrorStackTrace, JSNodePerformanceHooksHistogram, JSAbortAlgorithm, JSPerformance, JSDOMOperation, CryptoKey, and NodeHTTPParser. The only non-deletion is folding encode_append_impl into its sole caller encode_append (inlining the constant false for is_urlsafe).
Security risks
None introduced — only deletions. The touched ncrypto/webcrypto helpers (BignumPointer::encode, X509View::clone, HMACCtxPointer::digest, root(CryptoKey*), etc.) are unreferenced wrappers over BoringSSL; removing them cannot change runtime crypto behavior. No validation, auth, or TLS-gating logic is weakened.
Level of scrutiny
Medium. Each individual deletion is mechanical and self-verifying (a live reference would fail the link/compile, and the PR states bun bd + rust:check-all on all 12 targets pass). I spot-checked ~15 of the removed symbols with grep and found no remaining callers. The verification methodology (rg over src/codegen/packages/vendor + --gc-sections --print-gc-sections relink) is sound.
Other factors
The breadth (8+ subsystems, including ncrypto which is a vendored Node compat layer) and the note about coordinating with several other open dead-code PRs (#39929, #40232, #40367, #40294, #40172, #40122) suggest a maintainer should confirm none of the removed ncrypto surface is slated for imminent use. That coordination question, not correctness, is why I'm deferring rather than approving.
The generated extern "C" thunk roots the Rust implementation, so an export whose C++ caller was deleted compiles without a warning. The lint fails on the four exports this branch removes.
clippy.toml names bun_core::strings::split_once and rsplit_once as the sanctioned replacement for the denied str and bstr forms, so they stay. The lint now skips rust-abi markers (their consumers are extern "Rust" blocks, not C++) and pins git grep output format against user config.
There was a problem hiding this comment.
Thanks for addressing the earlier feedback — f3d78cd restored strings::split_once/rsplit_once, pinned the git grep output format with -c overrides, and now filters rust-abi markers out of the orphan check. I re-reviewed and found no bugs this pass. Given the breadth (21 files across ncrypto/webcrypto, JSC bindings, WebSocket client, timers) and that this adds a new CI-enforced source lint, a maintainer sign-off would still be worthwhile.
What was reviewed:
- Confirmed the three prior nits are resolved in f3d78cd (immutable.rs restored;
grep.lineNumber/grep.column/color.greppinned;rustAbiset excludes rust-abi markers). - Spot-checked
JSPerformance::toWrappedremoval againstJSDOMWrapperConverterTraits/IDLInterface<Performance>— no template callers found. - Verified the new lint's guard tests (
exports.size > 50,named.size > 50, duplicate detection) prevent vacuous passes.
Extended reasoning...
Overview
This PR deletes ~340 lines of dead code across 21 files: four orphaned Rust HOST_EXPORT thunks (WebSocket writeBlob × 2, initWithTunnel for TLS, drainTimers) plus their implementations; sixteen unused ncrypto helpers; assorted unreferenced C++ methods in JSC bindings (JSCStackFrame::typeName, HTTPParser::lessThan, one histogram create overload, JSAbortAlgorithm toJS/callbackData, JSPerformance::toWrapped, root(CryptoKey*), the String overload of throwNodeRangeError); and two Rust helpers (simdutf_encode_url_safe_alloc, CowSliceZ::init_unchecked). It also adds test/internal/source-lints/host-export-callers.test.ts, a new CI lint that fails if any HOST_EXPORT marker has no C/C++-side reference.
Since my previous review (three inline nits at c143bd4), commit f3d78cd restored bun_core::strings::{split_once, rsplit_once} (dropping the clippy.toml stale-reference concern entirely), added -c grep.lineNumber=false -c grep.column=false -c color.grep=never to the gitGrep helper, and made the MARKER regex capture the abi so rust-abi symbols are excluded from the C++ caller check. All three prior concerns are resolved.
Security risks
The deletions touch ncrypto and webcrypto (CryptoKey), which are crypto-adjacent. However, every removed item is a helper with no caller — verified by the PR author via rg over src/codegen/packages/vendor and a --gc-sections --print-gc-sections relink, and compilation on all 12 targets. Pure deletions of unreferenced symbols do not change runtime crypto behavior. No new attack surface is introduced. The new lint spawns git grep over the tracked tree with fixed pathspecs and no shell interpolation of untrusted input.
Level of scrutiny
Medium-high. Dead-code removal is mechanically verifiable (the compiler and linker are the ground truth), and the PR's methodology is thorough. But three factors push this past auto-approval: (1) breadth — 21 files across WebSocket client, timers, ncrypto, webcrypto, and multiple JSC binding subsystems; (2) the Ec class in ncrypto is reduced from a stateful wrapper to a static-method-only holder, which is a shape change to a vendored Node helper layer that a maintainer should confirm is desired; (3) the new host-export-callers lint is a CI policy addition that will gate every future PR adding a HOST_EXPORT marker, and REVIEW.md notes that new cross-cutting checks warrant maintainer agreement.
Other factors
The bug hunting system found nothing this run. I spot-checked JSPerformance::toWrapped for template-instantiated callers via JSDOMWrapperConverterTraits<Performance> / IDLInterface<Performance> and found none. The new lint now has guard tests against vacuous passes (marker count > 50, named count > 50, duplicate detection) and is hermetic against user git config. The PR description lists open dead-code PRs it deliberately avoided overlapping with, and calls out items it examined but left alone (e.g. root(MessagePort*) for an open PR).
|
@robobun binary size impact? |
|
None that the size check can measure. CI's binary-size step for the current head (
That is the expected result. Release links run with |
|
@robobun how can we be confident this doesn't break anything? and is strictly dead code? |
|
Two different arguments, one per kind of symbol. The C++ methods and the two Rust The four
Behavior cannot change because no code path changed: the diff is deletions plus one fold of Two items I removed earlier and then kept because the evidence was not that clean: |
Explain? |
|
Both are functions nothing calls that I chose not to delete in this PR.
|
ECKeyPointer::New(const EC_GROUP*) no longer exists on main. It was removed as dead code in #40413. TryParseECSubjectPublicKeyInfo was its only caller, so create the EC_KEY and set its group directly.
Problem
Bun__WebSocketClient__writeBlob,Bun__WebSocketClientTLS__writeBlob,Bun__WebSocketClientTLS__initWithTunnel, andBun__internal_drainTimers.WebSocket.cppconverts a Blob to bytes itself and callswriteBinaryData, and the tunnel path only creates the non-TLS client. TheHOST_EXPORTmarker roots each of them, so neither rustc nor hawk can see that they are dead.HTTPParser::lessThan, oneJSNodePerformanceHooksHistogram::createoverload,JSAbortAlgorithm::callbackDataandtoJS(AbortAlgorithm&),JSPerformance::toWrapped,JSCStackFrame::typeName,root(CryptoKey*), theStringoverload ofthrowNodeRangeError, and 16 ncrypto helpers.pubRust items have no caller in any crate:bun_base64::simdutf_encode_url_safe_allocandCowSliceZ::init_unchecked.Fix
WebSocketClient::write_blobgoes with its exports.encode_append_implfolds intoencode_append, its only remaining caller. The ncryptoEcclass keeps its one live member,GetCurveIdFromName.rgoversrc/,build/debug/codegen/,src/codegen/,packages/, andvendor/WebKitfinds no reference, and abun-debugrelink with--gc-sections --print-gc-sectionsdiscards each symbol.host_fn_this_valueandroot(MessagePort*)looked the same way and stay: codegen emits the first, and MessagePort: a close() made inside a handler completes after the drain loop, not inside close() #39841 is editingMessagePort.cpp, so the second waits for that fix to land.test/internal/source-lints/host-export-callers.test.ts: everyc/jscHOST_EXPORTmarker must be named by a C or C++ source. It fails on main with exactly the four exports above and passes here.bun bdbuilds,bun run rust:check-allpasses on all 12 targets,clang-formatandcargo fmtare clean. Rantest/js/web/websocket/(blob, client, bidir proxy),test/js/node/crypto/(crypto, ecdh, hmac, sign, x509),node-http,node-http-parser,perf_hooks, andabort.Background
// HOST_EXPORT(Name, c)marks a Rust fn thatsrc/codegen/generate-host-exports.tswraps in anextern "C"thunk for C++. The thunk exists whether or not C++ calls it, so an orphaned export compiles without a warning.src/jsc/bindings/ncrypto.{cpp,h}) is Bun's copy of Node's OpenSSL helper layer. Node still uses the removed helpers; Bun's callers never did.-Wl,--gc-sections -Wl,--print-gc-sectionslists every function section nothing references. A function that is discarded and also absent from the linked binary has no caller on that platform. Platform-gated code then needs a source check, which is why the darwin-onlyBun__noOrphans_*and the Windows-onlywindowsEnvbuiltin stay.Notes
Removed, by file:
src/http_jsc/websocket_client.rs:bun__websocketclient__write_blob,bun__websocketclienttls__write_blob,bun__websocketclienttls__init_with_tunnel,WebSocketClient::write_blob, and the now unusedJSValueimport.src/runtime/timer/Timer.rs:drain_timers_export(Bun__internal_drainTimers).src/base64/lib.rs:simdutf_encode_url_safe_alloc;encode_append_implfolded intoencode_append.src/ptr/CowSlice.rs:CowSliceZ::init_unchecked.src/jsc/bindings/node/http/NodeHTTPParser.{cpp,h}:HTTPParser::lessThan.src/jsc/bindings/JSNodePerformanceHooksHistogram.{cpp,h}:create(VM&, Structure*, JSGlobalObject*, HistogramData&&).src/jsc/bindings/webcore/JSAbortAlgorithm.{cpp,h}:callbackData(),toJS(AbortAlgorithm&),toJS(AbortAlgorithm*).src/jsc/bindings/webcore/JSPerformance.{cpp,h}:JSPerformance::toWrapped.src/jsc/bindings/ErrorStackTrace.{cpp,h}:JSCStackFrame::typeName,retrieveTypeName,m_typeName.src/jsc/bindings/webcrypto/CryptoKey.{cpp,h}:root(CryptoKey*)and theWebCoreOpaqueRootforward declaration and include it needed.src/jsc/bindings/webcore/JSDOMOperation.{cpp,h}:throwNodeRangeError(JSGlobalObject*, ThrowScope&, const String&); every caller passes anASCIILiteral.src/jsc/bindings/ncrypto.{cpp,h}:CryptoErrorList::add,CryptoErrorList::pop_front,BignumPointer::encode,BignumPointer::encodeInto,X509View::clone,BIOPointer::New(const BIO_METHOD*),BIOPointer::Write,EVPKeyPointer::bits,Cipher::EMPTY,ECKeyPointer::New(const EC_GROUP*),EVPKeyCtxPointer::derive,HMACCtxPointer::digest,Ec::Ec(),Ec::Ec(const EC_KEY*),Ec::getGroup, and theEcconversion operators and field.Scan summary for this run. Areas: Rust in
src/runtime,src/http_jsc,src/bun_core,src/base64,src/ptr, and the JSC bindings outside the files that open dead-code PRs (#39929, #40232, #40367, #40294, #40172, #40122) already touch; the TS builtins insrc/js.x86_64-unknown-linux-gnu,x86_64-pc-windows-msvc,aarch64-apple-darwin(release profile, perhawk.toml): 847dead_publicfindings. 668 are fields of FFI mirror structs (libuv.rs,windows_sys/externs.rs,boringssl.rs). Most of the rest are in files the open PRs own, are debug-only (has_resolve_breakpoint,StoredTrace::capture,ArrayHashMap::unlock_pointers), are codegen targets (host_fn_this_value), or are FFI enum mirrors (tty::Mode::Io,ImplementationVisibility).no-unused-vars,no-unused-private-class-members,no-unreachableoversrc/js: 0 findings. Nosrc/jsfile is unimported. No.rsfile is outside amodtree except the three[[bench]]targets.--gc-sectionsrelink ofbun-debug: 1005 non-generated discarded symbols, 283 of them in files no open PR touches. After removing sqlite3.c, llhttp, vendored shims, platform-gated code, and generatedZigGeneratedClasseshelpers, the list above is what remains.Possibly dead, left alone:
bun_core::strings::split_once/rsplit_once: no caller today, butclippy.tomlnames them as the replacement for the deniedstr::split_once/bstr::split_once_strforms. Kept as API surface.src/jsc/bindings/webcore/streams/JSCrossRealmTransformState.{cpp,h}(135 lines): theCrossRealmsource and sink kinds inStreamsForward.hare never constructed. It reads as scaffolding for stream transfer in the native streams work, so it stays.ECDSASigPointer,ECGroupPointer,ECPointPointer,HMACCtxPointer: default constructor, move constructor, andrelease()are unreferenced, but they are the smart-pointer idiom the rest of ncrypto follows.src/threading/Futex.rswasm_implandunsupported_impl: no shipped target compiles them.bun_core::Global::StoredTrace::{EMPTY, capture},has_resolve_breakpoint,ArrayHashMap::unlock_pointers,TaskTag::name: release-dead, used underdebug_assertions.