Skip to content

perf: optimize flattenWrapperElements with single-pass and cached depths#317

Open
Kikobeats wants to merge 2 commits into
kepano:mainfrom
Kikobeats:perf/flatten-wrapper-elements
Open

perf: optimize flattenWrapperElements with single-pass and cached depths#317
Kikobeats wants to merge 2 commits into
kepano:mainfrom
Kikobeats:perf/flatten-wrapper-elements

Conversation

@Kikobeats

Copy link
Copy Markdown

Replace the multi-pass do-while loop with a single bottom-up pass that
caches element depths, pre-computes callout containers, and hoists regex
patterns to function scope. This reduces O(n²) behavior on large DOMs
(e.g. 3.4MB shadow-DOM-flattened pages with 12k+ elements).

Benchmarks on roche.com/solutions/pipeline:

  • flattenWrapperElements: 823ms → 573ms (29% faster)
  • parseInternal overall: ~13% faster

Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com

Kikobeats and others added 2 commits June 14, 2026 12:38
Replace the multi-pass do-while loop with a single bottom-up pass that
caches element depths, pre-computes callout containers, and hoists regex
patterns to function scope. This reduces O(n²) behavior on large DOMs
(e.g. 3.4MB shadow-DOM-flattened pages with 12k+ elements).

Benchmarks on roche.com/solutions/pipeline:
- flattenWrapperElements: 823ms → 573ms (29% faster)
- parseInternal overall: ~13% faster

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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