Skip to content

FlatBuffers union members and block headers are matched in linear time - #357

Merged
zlareb1 merged 3 commits into
mainfrom
fix/fbs-union-member-linear
Nov 7, 2026
Merged

zlareb1 merged 3 commits into
mainfrom
fix/fbs-union-member-linear

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Bug Fix (user-visible misbehaviour in an official stable release)

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.py put 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 on main here; 700 blanks take 68 s.
  • _BLOCK_RE (: Base, (attributes)): about n³. table A, 2 000 blanks, x takes about 3 s on main.

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 a fullmatch of 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.py is 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

  • Wire: none.
  • Operator steps: none.
  • Rollback: revert.

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 are Rec and Record. Fails on main (about 3 s), passes here.
  • test_a_block_header_with_a_long_blank_run_is_read_in_linear_time: table A, 2 000 blanks, x is refused in under 0.5 s, and the headers after it, enum E : byte (bit_flags) and table T (x), still open blocks whose signatures (enum : byte, table (x)) pin the base type and attribute groups. Fails on main, 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 typecheck and make test-unit pass; the integration suite passes if server behaviour changed.
  • Generated files are regenerated in this PR, not by hand.
  • A new migration is additive and numbered after the latest on main; no merged migration is edited.
  • A behaviour change to any file a plugin ships bumps both plugin manifests' version.
  • The frontend builds and its tests pass, if frontend/ changed.
  • Docs under docs/ describe the system as it now is, and this description names any operator steps and wire changes.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers.
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.

🤖 Generated with Claude Code

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
zlareb1 force-pushed the fix/fbs-union-member-linear branch from c705965 to 6b3985d Compare November 7, 2026 12:00
…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]>
@zlareb1 zlareb1 changed the title A FlatBuffers union member is matched in linear time FlatBuffers union members and block headers are matched in linear time Nov 7, 2026
@zlareb1
zlareb1 merged commit 37563f6 into main Nov 7, 2026
38 checks passed
@zlareb1 zlareb1 mentioned this pull request Nov 12, 2026
3 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