Repository navigation
perf: batch DOM insertion through a DocumentFragment (v2.2.3) - #21
Merged
Merged
Conversation
Adding several items at once did one .after() per item, so inserting into an attached, already-large container paid that container's cost once per item. Each item is still rendered individually -- it needs its own Mustache pass and its own __jq_$el -- but the DOM write is now a single fragment insert. Covers splice() with multiple additions (and therefore push(...items) and unshift(...items)), __sortedBatchAdd, and __syncDomOrder, so sort(), reverse() and sorted inserts benefit too. A single-item insert keeps the old path, where building a fragment would be pure overhead. Measured in Chrome on rows with realistic markup, one batched push: 1,000 rows 134ms -> 103ms, 2,000 rows 613ms -> 374ms, 4,000 rows 1,274ms -> 1,013ms. `put` still sees an element that is in the document at every call site; __sortedBatchAdd previously called it before insertion, alone among the call sites, and now matches the rest. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TnJ9iEHU6m7kYxD5fXPfts
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.
Adding several items at once did one
.after()per item, so inserting into an attached, already-large container paid that container's cost once per item. Each item is still rendered individually — it needs its own Mustache pass and its own__jq_$el— but the DOM write is now a singleDocumentFragmentinsert.Covers
splice()with multiple additions (sopush(...items)andunshift(...items)),__sortedBatchAdd, and__syncDomOrder—sort(),reverse()and sorted inserts benefit too. A single-item insert keeps the old path, where building a fragment would be pure overhead.Measured
Chrome, rows carrying realistic markup (nested spans, badges, buttons), one batched push:
Behaviour
putis still called with the element already in the document at every call site.__sortedBatchAddpreviously called it before insertion, alone among the call sites; it now matches the rest.Checks
npm run test:typespassesdist/rebuilt (it is what consumers load viamain/browser)Context
Found while investigating a theta-directory tab reaching 4GB. jq-repeat turned out not to be the cause of that leak — a WeakRef test showed 0 of 500 rows retained after 9 replacement cycles and a forced GC. This is an independent improvement, not the fix for that bug.
🤖 Generated with Claude Code
https://claude.ai/code/session_01TnJ9iEHU6m7kYxD5fXPfts