Repository navigation
The wide-integer check builds a TOML key path in linear time under a tracer - #212
Merged
Merged
Conversation
…tracer The path was built with `+=`, which CPython extends in place only without a trace function; under coverage each step copied the path so far, and 20,000 levels of 1,000-character keys took over a minute. One join builds it. The test compares the time at 5,000 and 20,000 levels under a no-op tracer instead of a wall-clock bound. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Review nits: the separator goes on each key part and the join drops the first dot; the test's docstring names the 8x limit it asserts; sys and time are module imports. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
1 task done
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.
Changelog category (leave one):
Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):
Not required: the extractor service runs without a trace function, where the old path build was already linear; only the unit job under coverage was quadratic.
Why
Failing case: the unit job on
mainfailstests/unit/test_document_extraction.py::test_the_wide_integer_check_is_linear_in_a_deep_table_of_long_keys(66 s against a 5 s bound). The same test underpytest --covtakes 67.8 s locally and passes in well under a second without coverage.Pattern:
_entry_pathbuilt the key path withpath += part. CPython extends a string in place only when the specialized in-place add runs; under a trace function (coverage's, a debugger's) it does not, and each step copies the whole path so far. With a trace function set, 5,000, 10,000 and 20,000 levels of 1,000-character keys took 0.5 s, 2.2 s and about 9 s: quadratic. Without one they took 0.018 s, 0.035 s and 0.071 s, which is why the test passed outside CI.Fix: the path is built with one
"".join(...), linear with or without a tracer.The test no longer asserts a wall-clock bound. It sets a no-op trace function, times the check at 5,000 and 20,000 levels (best of three each) and asserts that four times the depth costs under eight times the time. A linear build gives about 4x, the old build 18.6x. A slower or shared runner slows both runs alike, so the ratio stays the same.
The other
_within(...)bounds in the same file cover the Markdown, HTML, SQL and TOML parsers, not this path build. No other string+=loop exists underextractor/, so they do not share this cause and are unchanged.Scope and risk
One helper in
extractor/loom_extractor/tomlfile.pyand its test. The path it returns is unchanged: thetest_a_toml_integer_outside_signed_64_bits_makes_the_file_invalid_tomland reopened-table cases still pass.Compatibility, rollout and rollback
Tests
AssertionError: 4x the depth took 18.6x the time. On the new code it passes in 0.49 s.pytest tests/unit/test_document_extraction.py -p randomly --cov=server --cov=sdk/python/loom --cov-branch: 187 passed. The test now takes under a second there, down from 67.8 s.make format lint typecheckpass.Other failures on
mainthis PR does not fix, which may still show red on its head: the integration teststests/integration/same_key/test_retirement_ch.py(two tests),tests/integration/test_memory_inspect.py::test_inspect_splits_own_from_others_and_changes_nothingandtests/integration/test_search_statements_pass_analyzer.py::test_patch_part_probe_and_reemit_reads_pass_the_analyzer.AI assistance in the code (leave one; writing this description with AI is fine):
AI-generated (an agent wrote most of the diff): Claude Code. Checked: the quadratic timing with and without a trace function, the new test failing on the old code, and the unchanged path output.
I can explain every line of this diff and how it interacts with the rest of Loom.
Checklist
make format-check,make lint,make typecheckandmake test-unitpass; the integration suite passes if server behaviour changed. (Format, lint, typecheck and this test file ran locally; the full unit suite runs in CI.)tests/unit/test_public_copy.py).git commit -s), as CONTRIBUTING.md asks.🤖 Generated with Claude Code