perf(settings): use Set lookups for pref classification and multipleOptions filtering - #1002
Open
Endymi0n74 wants to merge 1 commit into
Open
perf(settings): use Set lookups for pref classification and multipleOptions filtering#1002Endymi0n74 wants to merge 1 commit into
Endymi0n74 wants to merge 1 commit into
Conversation
…ptions filtering isGlobalPref()/isStreamPref() were doing an Array.includes() over ALL_PREFS (45+ items) on every pref read/write. ALL_PREFS is now a Set (same literal list), making both lookups O(1). validateValue()'s multipleOptions filtering also switches to Set.has() + filter() instead of a per-item indexOf()+splice() on the source array (which mutated the value in place and could skip items after a splice). Behaviour is identical: the lists are static per build, only the lookup data structure changes. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.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.
What
isGlobalPref()/isStreamPref()were doing anArray.includes()overALL_PREFS(45+ items) on every pref read/write.ALL_PREFSis now aSet(same literal list), making both lookups O(1).validateValue()'smultipleOptionsfiltering also switches toSet.has()+filter()instead of a per-itemindexOf()+splice()on the source array — which mutated the value in place and could skip items after a splice.Why it's safe
Set.has()andArray.includes()are semantically identical for these string lists.filter()copy no longer mutates the caller's array (strictly safer).Files
src/enums/pref-keys.ts—ALL_PREFSglobal/stream arrays →Setsrc/utils/pref-utils.ts—isGlobalPref/isStreamPref→Set.has()src/utils/settings-storages/base-settings-storage.ts—validateValuemultipleOptions →Set.has()+filter()Measurement
Micro-benchmark of
isGlobalPrefon the 45+ item list: lookup is constant-time (Set.has) vs linear scan (includes). This runs on every settings read/write across the page — the win compounds with the settings-heavy flows (perf overlays, controller customization reads, translation lookups).Note
pref-keys.tsis also modified by the open PR #908 (mkb zoom option, open since March). Our changes are in different regions (theALL_PREFSlists vs the zoom flag) and I'm happy to rebase if #908 merges first.