Skip to content

perf(settings): use Set lookups for pref classification and multipleOptions filtering - #1002

Open
Endymi0n74 wants to merge 1 commit into
redphx:typescriptfrom
Endymi0n74:feat/settings-set-prefs
Open

perf(settings): use Set lookups for pref classification and multipleOptions filtering#1002
Endymi0n74 wants to merge 1 commit into
redphx:typescriptfrom
Endymi0n74:feat/settings-set-prefs

Conversation

@Endymi0n74

Copy link
Copy Markdown

What

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.

Why it's safe

  • The lists are static per build — only the lookup data structure changes.
  • Set.has() and Array.includes() are semantically identical for these string lists.
  • The filter() copy no longer mutates the caller's array (strictly safer).

Files

  • src/enums/pref-keys.tsALL_PREFS global/stream arrays → Set
  • src/utils/pref-utils.tsisGlobalPref/isStreamPrefSet.has()
  • src/utils/settings-storages/base-settings-storage.tsvalidateValue multipleOptions → Set.has() + filter()

Measurement

Micro-benchmark of isGlobalPref on 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.ts is also modified by the open PR #908 (mkb zoom option, open since March). Our changes are in different regions (the ALL_PREFS lists vs the zoom flag) and I'm happy to rebase if #908 merges first.

…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>
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