Repository navigation
Fix quadratic heading ID generation for duplicate headings - #74
Merged
Merged
Conversation
Generate rescanned the numeric suffixes from 1 for every repeated heading, so a document with n identical headings cost O(n^2). Conversation logs have hundreds of identical "User" / "Claude" headings. Remember the last suffix per base ID instead; results are identical. Server render time for conversation-like Markdown: 1MB 0.165s -> 0.108s, 5MB 2.0s -> 0.54s, 10MB 7.2s -> 1.08s. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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.
Fixes #73
Summary
gfmIDs.Generaterescanned the numeric suffixes from 1 for every repeated heading (O(n^2) for n identical headings). It now remembers the last suffix handed out per base ID. Generated IDs are identical to before (suffixes below the remembered value are always taken, since IDs are never released).Measurements
Server render time, conversation-like Markdown:
BenchmarkConvert_DuplicateHeadings(20,000 identical headings): 14.3s -> 0.106s.Tests
a,a-2,a,a,a->a,a-2,a-1,a-3,a-4)Not included
Browser-side layout cost for very large pages (
content-visibility: autowas measured to help ~5x but changes scroll height estimation and anchor positioning).🤖 Generated with Claude Code