Repository navigation
Code-index lane walks read a file in linear time - #448
Merged
Merged
Conversation
zlareb1
force-pushed
the
sec/lane-walks-linear
branch
3 times, most recently
from
November 9, 2026 23:13
21bc1b5 to
e488af1
Compare
A Markdown heading's closing hashes are stripped in Python instead of by a pattern that backtracks cubically on a run of spaces while holding the GIL. Section ends, includes, setup.py entry points, Dockerfile rows, flags and stages, Jenkinsfile steps, template site lines, Vue macro members, dbt tags and raw blocks, CMake commands and route methods no longer rescan, slice or count the file from the top per item. setup.py layouts are read off the event loop. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
The Python route call patterns stop at the next same call, routes and environment reads take their lines by bisection through one shared helper, and an Angular inline template takes its line from its own offset. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
… namespace at a time Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
A heading title is cut to 1,000 characters, since every descendant's qualified name repeats it, and a Svelte event attribute is not searched from inside a modifier chain. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Each repeats every ancestor's title, so deep sections under long titles grew the output with depth times title length per section. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…camel-case modifiers name their handler Qualified names and heading paths are cut to 1,000 characters, a cut name ending in a hash of the whole. The event pattern reads camel-case modifiers, and a CMake command's line breaks before its `(` are counted. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
… test Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…efix cut is checked directly Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
… prefix is cut after its leading slash Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…cut in one place Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…over each per-method cut Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
zlareb1
force-pushed
the
sec/lane-walks-linear
branch
from
November 10, 2026 02:14
3572a08 to
761e2ea
Compare
This was referenced Nov 10, 2026
Merged
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):
The code index reads Markdown, Python layout manifests (
setup.py,pyproject.toml,conftest.pysets), Dockerfile, Jenkinsfile, Angular, Vue, Svelte, Astro and dbt files, CMake command rows, and route and environment-variable facets, in time linear in the file's size. A crafted file, in an indexed repository or in the files a request posts for the PR overlay, could hold a serving replica or the indexer for minutes to hours.Why
The language lanes outside tree-sitter walk a file with regular expressions and Python loops, and the parse deadline does not cover them. Several walks cost more than linear time on input a repository or a
pr_filescaller controls:^(#{1,6})\s+(.+?)\s*#*\s*$backtracks cubically on one heading line with a long run of spaces. Onere.matchcall holds the GIL, so the whole process stops, event loop included: about 1 s at 1,000 spaces, hours at 20 KB. The PR overlay parses posted Markdown files on the serving replica, so any reader of a code namespace reaches it.onof a|modifier chain);setup.pyconsole_scriptslists (each unclosed list scanned to the end, then rescanned from every later match, on the event loop); Dockerfile rows (continuation rows re-gathered per row),--flagstripping (a slice per flag) and stage ends (a scan of everyFROMper stage); a line count from the top of the file per site in Angular, Vue and Svelte templates, Angular component classes, Jenkinsfile steps,setup.pyentry points, Python routes, and environment-variable reads in Python and JavaScript/TypeScript; a router or controller prefix of any length joined into every route under it, and joined again on everyinclude_routercall; a route path of any length copied once per entry of itsmethodslist; Angular inline templates (a search from the top of the file per class); dbttags=[without a closing], routemethods=[, andinclude_router(,add_url_rule(andRoute(calls without a closing)(a regex scan to the end from each opener); the restore of{% raw %}blocks (a whole-text replace per block); Vue macro members (pop(0)per node); CMake commands (a slice of the rest of the file per row); Python layout roots frompyproject.toml,setup.pyandconftest.py(a list membership test per root).Each fix is the smallest one that makes the walk linear:
#s;rstripremoves them, with the same result as the old pattern on every line.bisect(one shared helper,text_lines.py, which replaces the copies inlang_sql_jinja.pyandts_routes.py), or a count carried forward; an Angular inline template's line comes from its own offset; the bracket and call-argument patterns stop at the next opener or the next same call; a Python route path is cut at 400 characters before it is joined to each method, a router's or NestJS controller's prefix at 400 characters after its leading slashes, twice what a route name keeps, and a TypeScript route name at 200 as a Python one is; raw blocks are restored in onere.sub; the Vue member walk pops from the end of a reversed stack; Dockerfile flags are stripped by one anchored possessive pattern; a CMake command is matched at its offset.setup.pylist scans resume after the list they scanned, so a"console_scripts": [inside an unclosed list is not read twice.layout_from_texts) runs in a thread, off the event loop, one read per namespace at a time; its roots are deduplicated through a dict.Scope and risk
\continuation rows; before, a continuation row that starts with an uppercase word was read as an instruction.setup.pyentry-point list inside one the scan leaves open is read once, as part of the outer list. The scan counts brackets without skipping strings or comments, so an unmatched[in a comment inside aconsole_scriptslist now files a followinggui_scriptsentry underconsole_scriptsonly; before, it was filed under both.on:submit|preventDefault={save}) names its handler through the event pattern; before, only a same-file function was found, through the prop pattern, so stored edges do not change. Anon…=attribute written directly after a|(a|onclick={f}) is not read.(counts that break in its own end line, and no longer shifts the line numbers of the commands after it.add_url_rule(orRoute(call whose arguments hold another opener of the same call before the), or aninclude_router(call that holds one before itsprefix=(one in a comment, say), is read from the inner opener; before, the outer call read on past it.tagslist or a routemethodslist with a bracket inside it gives no tags (or the default method); before, it read the list up to the first closing bracket.py_layouts.pyis in the extractor stamp (edge stage, Python family): the next round re-derives the edge rows of Python files once, and the chunk and guard rows that derive from them, with the same result apart from the nestedsetup.pylist difference above. The other modules are outside the stamp. Rows already stored keep the old values of the intended differences until their file is ingested again;loom code backfill --paths-filecorrects them sooner.answers.py,answers_cache.py,history.pyandmessage_grep.py. Their inputs are capped (2,000 to 20,000 characters) and they cost at most 30 ms at the cap.Compatibility, rollout and rollback
Tests
tests/unit/test_code_regex_cost.pycovers the new shapes. A# aprefix with a run of spaces, and a<word>=[unit per word a pattern spells, catch the heading, dbt tags and route methods patterns.test_a_lane_walk_costs_linear_timeruns each of 32 walks (tests/unit/lane_walks.py) at 100,000 and 400,000 characters in a child process, which arms a 60 sfaulthandlerdump and has a 120 s timeout, so a GIL-holding regression fails with the child's stack instead of hanging the suite. It asks for the 4N time to be under 5 s and under 8 times the N time, or under 0.1 s. Onmainall 32 fail (the heading line with spaces and thesetup.pylists by the deadline). The Python router-prefix cut stays under the ratio onmainat these sizes, sotest_code_py_symbols.pychecks the stored prefix's length instead. With the fix all pass. The Python route walks time the lane's call-site scans, not the file's tree-sitter parse, so the bound measures the walk.tests/unit/test_code_py_layouts.py::test_the_layout_is_read_off_the_event_loopfails onmainand passes here;test_files_that_miss_the_layout_cache_at_once_share_one_readchecks that concurrent misses share one read in the thread. The intended differences have a test each intest_code_host_islands.py,test_code_py_layouts.py,test_code_lang_angular.py,test_code_sql_jinja_dbt.py,test_code_py_symbols.py,test_lang_markdown.py,test_code_lang_svelte_astro.py,test_lang_cmake.pyandtest_code_routes.py.mainmodules over 3,000 random token mixes per lane, and 200,000 random heading lines and flag strings, also matched, apart from the Dockerfile continuation rows and the nestedsetup.pylist above.test_lang_markdown.py,test_code_host_islands.py,test_code_lang_angular.py,test_code_vue_lane.py,test_code_lang_svelte_astro.py,test_code_sql_jinja_dbt.py,test_lang_cmake.py,test_code_py_layouts.py, the route tests and the others that import these modules) pass.make format lint typecheckpasses.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. Each cost was measured in a child process before and after the fix, and the output was compared on real files and against the previous modules.
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.main; no merged migration is edited. (none)frontend/changed. (unchanged)docs/describe the system as it now is, and this description names any operator steps and wire changes.git commit -s), as CONTRIBUTING.md asks.🤖 Generated with Claude Code