Skip to content

The wide-integer check builds a TOML key path in linear time under a tracer - #212

Merged
zlareb1 merged 2 commits into
mainfrom
fix/wide-integer-path-join
Nov 3, 2026
Merged

zlareb1 merged 2 commits into
mainfrom
fix/wide-integer-path-join

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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 main fails tests/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 under pytest --cov takes 67.8 s locally and passes in well under a second without coverage.

Pattern: _entry_path built the key path with path += 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 under extractor/, so they do not share this cause and are unchanged.

Scope and risk

One helper in extractor/loom_extractor/tomlfile.py and its test. The path it returns is unchanged: the test_a_toml_integer_outside_signed_64_bits_makes_the_file_invalid_toml and reopened-table cases still pass.

Compatibility, rollout and rollback

  • Wire: none.
  • Operator steps: none.
  • Rollback: a revert leaves nothing behind.

Tests

  • New test on the old code: 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 typecheck pass.

Other failures on main this PR does not fix, which may still show red on its head: the integration tests tests/integration/same_key/test_retirement_ch.py (two tests), tests/integration/test_memory_inspect.py::test_inspect_splits_own_from_others_and_changes_nothing and tests/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 typecheck and make test-unit pass; the integration suite passes if server behaviour changed. (Format, lint, typecheck and this test file ran locally; the full unit suite runs in CI.)
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers; the history goes in this description (tests/unit/test_public_copy.py).
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.

🤖 Generated with Claude Code

zlareb1 and others added 2 commits November 3, 2026 11:33
…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]>
@zlareb1
zlareb1 merged commit 66c7146 into main Nov 3, 2026
17 of 18 checks passed
@zlareb1
zlareb1 deleted the fix/wide-integer-path-join branch November 3, 2026 12:48
@pufit pufit mentioned this pull request Nov 4, 2026
9 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant