You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Lockfiles can retain valid but non-canonical whitespace, creating avoidable merge conflicts while --locked continues to accept them. Add the lockfile-format-check preview feature and stream toml_parser tokens during locked checks to reject malformed indentation and separators with the offending line, keeping formatting out of the stable lockfile contract and allowing offline validation without a refresh.
I benchmarked the final streaming toml_parser check on a normal-sized lockfile and the 15.8 MB dependency lock that motivated this change. The late-format case adds one trailing space immediately before the final newline, so the TOML remains valid and the first formatting difference is on the final line; the checker must scan the entire file.
Fixture
Bytes / lines
Parse
Parse + check
Paired added cost
Check only
uv lock, formatted
292,865 / 1,649
1.697 ms
1.855 ms
+0.154 ms
0.145 ms
uv lock, diff at end
292,866 / 1,649
1.671 ms
1.824 ms
+0.158 ms
0.145 ms
large lock, formatted
15,833,578 / 302,888
238.104 ms
253.807 ms
+16.164 ms
12.766 ms
large lock, diff at end
15,833,579 / 302,888
239.593 ms
254.910 ms
+14.433 ms
12.719 ms
For comparison, serializing the already-parsed Lock and comparing the resulting TOML adds substantially more work:
Fixture
Exact serialize + compare
uv lock, formatted / diff at end
2.384 ms / 2.362 ms
large lock, formatted / diff at end
265.284 ms / 271.681 ms
The streaming check adds about 0.15 ms for the normal lock and about 13-16 ms for the large lock (roughly 6-9% of deserialization), including the worst case where the first formatting error is at the end. Exact reserialization is about 16-21x more expensive than the streaming check here and roughly doubles the large-lock parse cost.
Measurements used optimized Rust (rustc 1.97.0, -C opt-level=3) on arm64 macOS. Parse and parse-plus-check samples were interleaved with alternating order to reduce drift: 120 paired parse / 500 check-only samples for the normal lock and 20 / 160 for the large lock. The checker streams tokens and does not collect the token vector. It checks serialization shape/whitespace, not semantic key ordering; an exact byte-for-byte canonicality check would require the more expensive reserialization path.
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
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.
Lockfiles can retain valid but non-canonical whitespace, creating avoidable merge conflicts while
--lockedcontinues to accept them. Add thelockfile-format-checkpreview feature and streamtoml_parsertokens during locked checks to reject malformed indentation and separators with the offending line, keeping formatting out of the stable lockfile contract and allowing offline validation without a refresh.