Replace per-save-point array snapshots with an undo trail - #870
Merged
Merged
Conversation
natecook1000
force-pushed
the
savepoint-simplify
branch
3 times, most recently
from
August 27, 2026 04:20
bb51e50 to
819dd70
Compare
Creating a save point previously copied the four mutable register arrays (ints, positions, values, and storedCaptures) to enable restoration during backtracking. This led to a large amount of reference counting traffic and copy-on-write of the original register arrays whenever they were updated. This change moves the restoration data from using full copies of each array in every save point, to tracking a log of the changes to each array in the processor itself and only storing the current state of the logs in each save point. This allows `SavePoint` to be a trivial type (almost) and removes all the copy-on-write traffic. Backtracking now uses the tracking logs to unwind the registers to the specific previous state. This change also includes a minor refactor, moving the `storedCaptures` array to the `Registers` struct, alongside the other mutable registers. Future work includes breaking out the mutable registers into their own type, creating a flat structure for these instead of maintaining four different dynamically allocated arrays, and moving further toward making `SavePoint` trivial.
natecook1000
force-pushed
the
savepoint-simplify
branch
from
August 27, 2026 04:32
819dd70 to
a00ae3d
Compare
Member
Author
|
@swift-ci Please test Linux platform |
This combines the current position and current range into a single enum along with the semantic Boolean that only applies to range- based save points. The log counts are also dropped to 32-bit integers, shrinking the overall size of `SavePoint` from 76 bytes to 40.
Doing the isDirty check inside the UndoableArray was losing out on the early exit for Registers.reset().
natecook1000
force-pushed
the
savepoint-simplify
branch
from
September 16, 2026 14:54
c329f13 to
f20815f
Compare
Member
Author
|
@swift-ci Please test Linux platform |
AnthonyLatsis
added a commit
that referenced
this pull request
Sep 22, 2026
natecook1000
added a commit
that referenced
this pull request
Sep 23, 2026
Creating a save point previously copied the four mutable register arrays (ints, positions, values, and storedCaptures) to enable restoration during backtracking. This led to a large amount of reference counting traffic and copy-on-write of the original register arrays whenever they were updated. This change moves the restoration data from using full copies of each array in every save point, to tracking a log of the changes to each array in the processor itself and only storing the current state of the logs in each save point. This allows `SavePoint` to be a trivial type (almost) and removes all the copy-on-write traffic. Backtracking now uses the tracking logs to unwind the registers to the specific previous state. This change also includes a minor refactor, moving the `storedCaptures` array to the `Registers` struct, alongside the other mutable registers.
JacobHearst
pushed a commit
to JacobHearst/swift-experimental-string-processing
that referenced
this pull request
Sep 28, 2026
…iftlang#870)" This reverts commit d25aa38.
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.
Creating a save point previously copied the four mutable register arrays (ints, positions, values, and storedCaptures) to enable restoration during backtracking. This led to a large amount of reference counting traffic and copy-on-write of the original register arrays whenever they were updated.
This change moves the restoration data from using full copies of each array in every save point, to tracking a log of the changes to each array in the processor itself and only storing the current state of the logs in each save point. This allows
SavePointto be a trivial type (almost) and removes all the copy-on-write traffic. Backtracking now uses the tracking logs to unwind the registers to the specific previous state.This change also includes a minor refactor, moving the
storedCapturesarray to theRegistersstruct, alongside the other mutable registers. Future work includes breaking out the mutable registers into their own type, creating a flat structure for these instead of maintaining four different dynamically allocated arrays, and moving further toward makingSavePointtrivial.