perf(pglite): reduce per-row allocation in parseResults#1050
Open
huntiezz wants to merge 1 commit into
Open
Conversation
Hoist field names and type OIDs once per result set on rowDescription, then build rows with indexed loops instead of Object.fromEntries and per-row .map(). Adds unit tests for parseResults covering object/array row modes, multi-result sets, and custom parsers.
add5c8e to
2433e52
Compare
Contributor
|
@huntiezz you mention "optimize" - do you have any benchmarks showing what the actual gains might be? |
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.
Summary
Optimizes the hottest JS-side path in PGlite — converting PostgreSQL wire-protocol
DataRowmessages into JavaScript objects/arrays inparseResults().Problem: Every row previously allocated intermediate structures:
Object.fromEntries(msg.fields.map(...))— builds a[key, value][]array per row, then iterates it againmsg.fields.map(...)— callback-based allocation per rowField names and type OIDs were also re-read from
currentResultSet.fields[i]on every row even though they're constant for the entire result set.Fix:
fieldNames[]andfieldTypes[]once per result set onrowDescriptionforloop (noObject.fromEntries)new Array(n)and fill by indexcommandCompleteThis is a behavior-preserving micro-optimization — a natural follow-up to #495, focused on large result-set workloads (#630). Does not overlap with maintainer drafts #973 (parse redesign) or #903 (streaming parse).
Test plan
packages/pglite/tests/parse.test.ts(9 cases: object/array modes, multi-result sets, INSERT/UPDATE/DELETE counts, custom parsers, blob attachment, describe helper)pnpm vitest tests/parse.test.ts— 9 passedpnpm test:basic— 278 passed (57 files)pnpm stylecheck && pnpm typecheck— clean@electric-sql/pglitepatch