Repository navigation
Conversation
The session splices the encoded event into its message instead of parsing it back and stringifying it again. The client revives tags only when the message text holds one, so untagged events (game frames) are parsed once. The wire text is unchanged. Refs #260
The codec uses Uint8Array.prototype.toBase64 when the runtime has it (Bun, Node, recent browsers) and keeps the btoa loop for the others. An 8 MiB readMany answer no longer blocks the server for about 100 ms. The base64 text is unchanged. Refs #270
RpcSession.receive took any sub or unsub id the client sent. It now ignores ids that are not safe integers, as it ignores other broken messages. The client's ids are its integer counter, so nothing changes for it.
The codec uses Uint8Array.fromBase64 when the runtime has it and keeps the atob loop for the others. It accepts and refuses the same texts.
The replacer looked at the value after toJSON ran, so a Buffer went out as
{ type: 'Buffer', data: [...] } instead of a $bin tag. It now checks the
raw value first, like the Date branch.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Closes #260
Closes #270
Codec-level performance fixes in
@nanoforge-dev/editor-rpc, plus two small fixes found on the way. The wire text of stream events and the base64 text are unchanged; the one encoding change is a NodeBuffer, which now goes out as bytes (below).RpcSession._emitsplicesencode(event)into the message instead of encode, parse, stringify.RpcClientrevives$bin/$datetags only when the message text holds one, so untagged events (game frames) are parsed once. An event that isn't a JSON value now throws aTypeErrorinstead of aSyntaxError.encodeusesUint8Array.prototype.toBase64when the runtime has it (Bun, Node, recent browsers), with thebtoaloop as fallback.Bufferis not used because the codec also runs in the browser.fromBase64usesUint8Array.fromBase64when present, with theatobloop as fallback. Both accept and refuse the same texts; callers already turn a decode error intoBAD_REQUESTor "Unexpected response".RpcSession.receiveignoressub/unsubmessages whose id is not a safe integer, as it already ignores other broken messages. The editor's client only sends its integer counter.Buffer: the replacer checks the raw value beforetoJSONruns, so aBufferis sent as a$bintag instead of{ type: 'Buffer', data: [...] }.How do you test this PR?
Before/after (ms per op, minimum of 5 runs; the bench calls the real
RpcSession._emit,RpcClient._receive,encodeanddecode, built from each revision):readManyanswerThe client side runs in the browser; node gives a V8 number, Chrome itself was not measured. Every bench run checked that the wire text and the base64 text match the old code.
Tests (
packages/rpc/test):$binlook-alike,"$bin":inside a string, U+2028), base64 parity withbtoa/atob, and both fallbacks with the native functions removed. These are equivalence guards: they pass on the old code too.{"content":{"type":"Buffer","data":[1,2]}}; after{"content":{"$bin":"AQI="}}, 22/22.Commands run from the worktree on a8a1383:
pnpm build(17/17),pnpm lint(29/29, knip included),pnpm typecheck, and the unit tests of every dependent package: code 48, project 63, runtime 13, settings 27, rpc 22, server-core 129, all passed, 0 skipped. Not run on this branch alone:packages/ui, the plugins, e2e.Integration: a scratch branch with every editor branch of this sweep merged passed
pnpm build, lint, typecheck,pnpm test --force(1014 passed, 1 skipped) and the full e2e suite with the engine (141/141, Chromium only).Merge danger
@nanoforge-dev/editor-rpcis private, with 7 runtime dependents in the editor (code, project, protocol, runtime, server-core, settings, ui).hasTagsis a new export of the package; the SDK re-exports only named symbols, so its public surface is unchanged. Merging tomaindeploys the editor app.Follow-up issues
None filed. A binary response for
read/readMany(suggested in #270) stays a possible next step.Quality gate
Last round 9eee610 (Buffer as bytes) and a8a1383 (style): producer red→green, not re-reviewed.