Repository navigation
perf(zero-rust): store a row's columns by its table's layout - #172
Merged
Merged
Conversation
A json::Object keeps its keys apart from its values, in a list that the rows of a table share (their layout), as Swift keys rows by column index and JS engines share hidden classes. The parser follows a recent object's keys while the next object has the same ones, so a synced row allocates neither its keys nor their list; the poke handler and mutators put rows in their table's layout. Comparators and filters remember where their column was, so they find it without searching the names. Conformance is unchanged: 63,453 cases, 0 failures. Amp-Thread-ID: https://ampcode.com/threads/T-01a1c6b9-fc99-73a1-bf70-e71fd484042c Co-authored-by: tmm <tmm@tmm.dev>
Rust, Swift, and JS measured on one machine, with a zero-rust patch changeset. Amp-Thread-ID: https://ampcode.com/threads/T-01a1c6b9-fc99-73a1-bf70-e71fd484042c Co-authored-by: tmm <tmm@tmm.dev>
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.
Large views, as the Space goal asks: store a row's columns by its table's layout instead of a per-row copy of every column name.
json::Objectkeeps its keys apart from its values (Arc<Keys>+Arc<[Value]>), and the rows of a table share one key list, their layout. This is the Rust counterpart of Swift keying rows by column index and of JS hidden classes.id) still share.Layouts, shared by a branch and its forks).get_hinted), and check the key there before using it.Public API is unchanged:
ObjectandOrderedMapkeep their methods, and the new ones arepub(crate).Numbers (medians of 3 interleaved runs on one 8-core Xeon orb)
At 100k rows, the cost per row compared with 10k went from 3.1× to 1.9×, about Swift's 2.0× on the same machine. It doesn't scale linearly yet.
Caveat:
swift/BENCHMARKS.md's Linux column has Swift 2–3× faster than it ran here (7.07 ms for 100k rows), while JS ran exactly as fast as documented. Against that column, Rust is behind Swift at 100k rows (10.5 vs 7.07 ms) and level on structs (23.8 vs 24.8 ms). It's written up inrust/BENCHMARKS.md.Small costs: a 1-row poke is about 1 µs slower, because sharing a row's layout compares its column names.
pk = N, an optimistic update and a round trip are 3–4% slower. A table's layout is one stored row per table. Locally inserted rows whose column order differs from the server's switch the layout back and forth: results stay correct, and those rows share less.Checks
-D warnings, workspace tests, docs with-D warnings, and MSRV 1.88 all pass.Adds a
zero-rustpatch changeset. Releasing it needs tmm.Amp-Thread-ID: https://ampcode.com/threads/T-01a1c6b9-fc99-73a1-bf70-e71fd484042c