Repository navigation
Conversation
When building its trigger list, each Collapse ran a document-wide `querySelectorAll` for every `[data-bs-toggle="collapse"]` on the page just to check whether the result contained its own element. Use `this._element.matches(selector)` instead, which gives the same answer without querying the document. Time to initialize every collapse on a page with N collapses (headless Chromium 141, one run each): N=100: 84 ms -> 39 ms N=500: 6.7 s -> 2.7 s N=1000: 52.9 s -> 18.6 s Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RCK6vggtNiub9nuny85at8
This branch has not been deployed
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.
Requested by Najeeb · project thread
Description
When a Collapse builds its trigger list, it runs
SelectorEngine.find(selector)(a document-widequerySelectorAll) for every[data-bs-toggle="collapse"]on the page, only to check whether the result contains its own element. This change usesthis._element.matches(selector)instead, which answers the same question without querying the document.Motivation & Context
On pages with many collapses (long FAQs, accordions, tables with expandable rows), initialization cost grows quickly. Time to initialize every collapse on a page with N collapses, headless Chromium 141, one run each:
Benchmark: N pairs of
<button data-bs-toggle="collapse" data-bs-target="#cI">and<div class="collapse" id="cI">, thenCollapse.getOrCreateInstance(el, { toggle: false })on each, timed withperformance.now().Type of changes
Checklist
npm run lint)Existing trigger tests cover this path;
npm run js-test-karma: 809 of 809 pass.