Skip to content

fix quadratic reindent of wide identifier lists#851

Open
alhudz wants to merge 1 commit into
andialbrecht:masterfrom
alhudz:reindent-identifierlist-quadratic
Open

fix quadratic reindent of wide identifier lists#851
alhudz wants to merge 1 commit into
andialbrecht:masterfrom
alhudz:reindent-identifierlist-quadratic

Conversation

@alhudz

@alhudz alhudz commented Jun 8, 2026

Copy link
Copy Markdown
  1. ReindentFilter._process_identifierlist puts each column on its own line via insert_before(token), which resolves the position through TokenList.token_index.
  2. token_index ran self.tokens[start:].index(token), copying the list tail and rescanning from 0 on every call, so an N-column list reindented in O(n^2).

repro: sqlparse.format('select ' + ','.join('a' for _ in range(16000)), reindent=True)
before: reindent step ~3.5s; a 4000-column SELECT (~8 KB, under the 10000-token cap) ~0.5s
after: reindent step ~0.12s; same 4000-column SELECT ~0.2s

fix: token_index now uses self.tokens.index(token, start) (no copy, honours the hint) and the loop keeps a forward cursor. Parse output is unchanged.

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