Skip to content

perf: O(1) blacklist lookup in BlacklistStorage.isListed - #38

Open
iamthealfaandtheomega wants to merge 1 commit into
RayzsYT:mainfrom
iamthealfaandtheomega:pr5-tab-optimization-main
Open

iamthealfaandtheomega wants to merge 1 commit into
RayzsYT:mainfrom
iamthealfaandtheomega:pr5-tab-optimization-main

Conversation

@iamthealfaandtheomega

Copy link
Copy Markdown

Summary

Optimizes BlacklistStorage.isListed(), the hot path behind PlayerCommandSendEvent. The membership check stays O(1) HashSet, but the query lookup now uses precomputed raw + first-arg-normalized sets so both the verbatim and the takeFirstArgument path match correctly against full stored entries.

What changed

  • Precomputed rawLookup (verbatim) and firstArgLookup (first-arg-normalized) caches derived from hiddenCommands.
  • Hot path: single O(1) contains() — no scan.
  • rebuildLookups() builds into local sets and atomically swaps the references only after full population (a concurrent reader never sees an empty/partial set).
  • Locale.ROOT normalization (was default-locale toLowerCase() — locale-sensitive).
  • Dirty-flag defers the O(n) rebuild off add()/remove()/clear() → bulk imports stay O(1) per mutation.
  • Mutations + iteration are synchronized; caches are transient volatile.
  • clear() now also clears hiddenCommands (was leaving the cache stale).

Behavior preserved

  • Same semantics for normal/negated commands, blacklist/whitelist (turn), case sensitivity, plugin-command expansion, and the load() pipeline (unchanged).

Verification

  • 10 unit tests (local) pass covering getFirstArg + lookup normalization invariance.
  • Compiles clean with -Xlint:deprecation/-Xlint:unchecked (only pre-existing warnings elsewhere).

Keep the existing HashSet membership but add precomputed raw + first-arg-normalized
lookup sets so the hot path is a single O(1) contains for both verbatim and
first-arg (takeFirstArgument) matches, fixing the case where main's approach could
miss first-arg-stripped queries against full stored entries.

- Locale.ROOT normalization (was default-locale toLowerCase()).
- transient volatile sets, atomically swapped after full build (no empty/partial
  set visible to concurrent readers).
- dirty-flag defers the O(n) rebuild off add()/remove()/clear() (bulk O(1)/op).
- synchronized mutations + iteration; clear() also clears hiddenCommands.
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