Repository navigation
FlatBuffers union members and block headers are matched in linear time - #357
Merged
Merged
Conversation
Each optional part of the union-member pattern now owns the blanks before it, so a long blank run is read one way only instead of being split between three adjacent \s* runs. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
zlareb1
force-pushed
the
fix/fbs-union-member-linear
branch
from
November 7, 2026 12:00
c705965 to
6b3985d
Compare
…on test checks the members' edges _BLOCK_RE put a \s* before and after each optional part (base type, attributes), so a header that never opens its block (`table A`, 2 000 blanks, `x`) took about 3 s, cubic in the blanks. Each optional part now owns the blanks before it, as the union member pattern does; on ordinary headers the groups are the same. The union member pattern is a fullmatch of one stripped member, with no anchors or separators it never sees. The union test asserts the members' external edges (Record, and Rec through the alias), and both timing tests use inputs main finishes in seconds, so a regression fails instead of hanging. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…oups Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
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):
Indexing a FlatBuffers schema with a long run of blanks inside a union member or a block header no longer stalls the code-index worker.
Why
Two regexes in
server/code/domain/extract/lang_flatbuffers.pyput a\s*on both sides of each optional part, so on a line that cannot match the engine tries every way of splitting a blank run between the adjacent\s*runs before it refuses the line. The schema is repository content, so one indexed file can hold the worker._UNION_MEMBER_RE(: Type,= N): about n⁴ in the blanks.ab, 300 blanks,_takes about 3 s onmainhere; 700 blanks take 68 s._BLOCK_RE(: Base,(attributes)): about n³.table A, 2 000 blanks,xtakes about 3 s onmain.The timings are CPU seconds on a shared, loaded development machine.
Each optional part now owns the blanks before it (
(?:\s*:\s*T)?(?:\s*=\s*\d+)?), so a blank run is read one way only. The union pattern is now afullmatchof one stripped member between commas, without the anchors and separators that input never holds. On ordinary input both patterns match what they matched before, with the same groups.Scope and risk
Two regexes and their tests.
lang_flatbuffers.pyis not in the extractor stamp's module list and its output on ordinary input is unchanged, so nothing is re-indexed.Compatibility, rollout and rollback
Tests
test_a_union_member_with_a_long_blank_run_is_read_in_linear_time: a union with a non-matching member and an aliased one, each after 300 blanks, parses in under 0.5 s, and its external edges areRecandRecord. Fails onmain(about 3 s), passes here.test_a_block_header_with_a_long_blank_run_is_read_in_linear_time:table A, 2 000 blanks,xis refused in under 0.5 s, and the headers after it,enum E : byte (bit_flags)andtable T (x), still open blocks whose signatures (enum : byte,table (x)) pin the base type and attribute groups. Fails onmain, passes here.tests/unit/test_lang_flatbuffers.py: 5 passed.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; the regex was checked against the old one's matches by hand.
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.frontend/changed.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