Repository navigation
Conversation
|
PR author is not in the allowed authors list. |
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.
Motivation
Processing large values synchronously can block the event loop, delaying timers, I/O, and other application work.
This change adds asynchronous APIs for transport-boundary processing without changing the existing synchronous APIs.
Summary
serializeAsyncanddeserializeAsyncas instance, static, and named exports.yieldRatewith a default of1024.serializeanddeserializeAPIs unchanged.Measured effect
Benchmark setup
dist/index.jsThe synchronous serialized payload was created once and reused for all deserialization cases.
Each case was run once in the same Node.js process. The benchmark was started with
--expose-gc;global.gc()was called between cases, followed by a 20 ms settling period.Immediately before each operation, a 1 ms interval timer was started. The benchmark recorded elapsed time, timer callbacks until completion, and the maximum timer gap. The maximum gap includes time during which the operation blocked timer callbacks.
serializeserializeAsync,yieldRate=1serializeAsync,yieldRate=1024serializeAsync,yieldRate=8192serializeAsync,yieldRate=65536deserializedeserializeAsync,yieldRate=1deserializeAsync,yieldRate=1024deserializeAsync,yieldRate=8192deserializeAsync,yieldRate=65536These are single-run directional measurements and may vary with CPU load, garbage collection, and operating-system scheduling.
yieldRate=1causes substantial scheduling overhead. In this measurement, the defaultyieldRate=1024keeps serialization close to the synchronous baseline while allowing timer callbacks to run. Higher values reduce overhead further but allow longer uninterrupted processing periods.Impact and overhead
The overhead applies only to the asynchronous APIs. Existing synchronous consumers are unaffected.
yieldRatecontrols the trade-off between responsiveness and throughput: lower values yield more frequently but add overhead, while higher values reduce overhead but allow longer uninterrupted processing. The default is1024and can be adjusted for the workload.