Repository navigation
perf: compile field name transformation row mappers into object literals - #828
Merged
Merged
Conversation
🦋 Changeset detectedLatest commit: 13acc2a The changes in this PR will be included in the next version bump. This PR includes changesets to release 14 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Merged
This branch was previously deployed
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.
Improves the performance of
slonik-interceptor-field-name-transformation, and fixes two cases in which it reused the transformation of a different set of fields.Performance
transformRowused to copy every row one property at a time into a null-prototype object (Object.create(null)). V8 keeps such objects in dictionary mode, which makes them slow to create, and slow to read for everything that consumes the rows afterwards.Rows are now copied by a function that is compiled once per set of fields and returns an object literal, e.g.
(row) => ({ "fooBar": row["foo_bar"], "id": row["id"] }). Rows whose field names do not need to be transformed are returned as they are.200,000 rows of 12 fields, through
transformRow, Node 26:transformRow__proto__is defined using a computed key, because a literal"__proto__": valueproperty sets the prototype.Rows are now plain objects (they used to have a null prototype).
Fixes
The transformation is cached per set of fields. The cache key was the field names joined with
,, so:["foo_bar,baz_qux"]and["foo_bar", "baz_qux"];testreceives the whole field (includingdataTypeId).The key now consists of the field names and types, joined with a NUL character (which cannot appear in field names).
Tests
8 new tests: plain objects, passthrough,
__proto__, special characters in field names, both cache key cases, and thattestruns once per set of fields. They pass both with the compiled row mapper and with the fallback (--disallow-code-generation-from-strings).Note: on macOS, this package's tests do not run locally (
avareports "No tests found"): the path of the tsimp daemon socket in this package is 106 characters long, which is longer than macOS allows for a Unix socket path. CI (Linux) is not affected.