perf: materialize query results once - #320
Open
huytdps13400 wants to merge 1 commit into
Open
Conversation
7 tasks
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
resultsgetter once when building the JS-compatible rows object_array,length, anditem(index)share that single materialized arrayFixes #310.
Why
resultsis a HybridObject getter that returns the native result vector by value. The previousrows.item(index)closure evaluated that getter for every item, so traversing N rows requested N additional full result vectors. Caching the first materialization preserves the public result shape while removing the quadratic copy pattern.Benchmark
Synthetic getter-copy benchmark using Bun 1.3.14, six-column rows, one warm-up plus 20 measured iterations. The getter conservatively returns a shallow array copy; timings include wrapper construction and the named consumer.
item()traversalitem()traversalitem()traversalFor direct
_arrayandlengthconsumers, getter reads drop from 2 to 1 at every size. At 10,000 rows their median wrapper-plus-access time drops from about 0.014 ms to 0.006–0.008 ms in the same conservative benchmark.The committed real-device harness coverage also traverses all items for 60, 1,000, and 10,000 rows through both
executeandexecuteAsync.Verification
bun typecheckbun lintbun sqlite buildassembleDebugsucceeded across all configured ABIsmain(5 getter reads for two rows) and green on this branch (1 read)bun sqlite test --runInBandis currently blocked before test discovery by the repository's React Native 0.85 preset migration (react-nativenow requires@react-native/jest-preset). The real React Native harness suites above pass on both platforms.