Skip to content

avoid quadratic group value recomputation in TokenList#848

Open
alhudz wants to merge 1 commit into
andialbrecht:masterfrom
alhudz:tokenlist-value-quadratic
Open

avoid quadratic group value recomputation in TokenList#848
alhudz wants to merge 1 commit into
andialbrecht:masterfrom
alhudz:tokenlist-value-quadratic

Conversation

@alhudz
Copy link
Copy Markdown

@alhudz alhudz commented Jun 1, 2026

group_tokens and TokenList.init recompute a group's value by deep-flattening its whole subtree, so grouping an N-element identifier list is O(N^2): a 4000-column SELECT (~23 KB, under the 10000-token cap) takes ~1.8s to parse. Build the value from the direct children's already-current values and append only the newly added tokens on extend. Linear time, byte-identical parse output, full test suite passes.

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