interp: avoid repeated object clones on partial stores#5368
Open
jakebailey wants to merge 1 commit intotinygo-org:devfrom
Open
interp: avoid repeated object clones on partial stores#5368jakebailey wants to merge 1 commit intotinygo-org:devfrom
jakebailey wants to merge 1 commit intotinygo-org:devfrom
Conversation
memoryView.store cloned the entire destination object on every partial
store. Compiling a program that pulls in golang.org/x/text/collate hit
this hard: its generated tables are initialized one element at a time,
and each element store copied the whole global, making interp quadratic
in the table size.
Switch to copy-on-first-write per memory view: clone the object the
first time this view writes to it, then mutate that private copy in
place on later partial stores. Rollback is unaffected because revert
still discards the view's objects wholesale.
Two extra safety tweaks fall out of this:
- Full overwrites now clone the incoming value, so the stored buffer
can never alias state held by the caller.
- Partial in-place stores snapshot the source buffer, so a store
whose source is a load from the same object (overlapping or not)
still sees the pre-store bytes.
Add an interp golden test exercising both the overlapping load/store
case and a cross-object aliased load/store case.
Member
Author
|
I mistakenly benchmarked on non-wasip1 but the effect is about the same in absolute time (Wasm just has extra steps I have optimized in other places but not on this branch; other PRs coming) |
Member
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.
memoryView.storecloned the entire destination object on every partial store.tsgoimportsgolang.org/x/text/collateand hits this badly. The generated tables are initialized one element at a time, and each element store copied the whole global, makinginterpquadratic in the table size.By avoiding this copy until needed, we can greatly improve the perf.
devhttps://jakebailey.dev/how-much-faster/#old=369&new=232 1.59x faster 😄