Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[perf] Cache chat command prefix lookup in OnChat#3230

Open
Xekep wants to merge 1 commit intoPryaxis:general-develfrom
TerraZ-Team:pr/micro-perf-chat-prefix-cache-clean
Open

[perf] Cache chat command prefix lookup in OnChat#3230
Xekep wants to merge 1 commit intoPryaxis:general-develfrom
TerraZ-Team:pr/micro-perf-chat-prefix-cache-clean

Conversation

@Xekep
Copy link

@Xekep Xekep commented Feb 28, 2026

This code runs on every chat message that uses command ids.

This patch removes per-message iteration over localized commands and uses direct lookup through EnglishLanguage.GetCommandPrefixByName.

Behavior stays the same; it only reduces work in chat reconstruction.

Replace per-message iteration over ChatManager localized commands with direct lookup through EnglishLanguage.GetCommandPrefixByName using the command id name.

This aligns command reconstruction with the cached vanilla command map and removes unnecessary hot-path enumeration in OnChat.
@greptile-apps
Copy link

greptile-apps bot commented Feb 28, 2026

Greptile Summary

Optimized chat command prefix lookup in OnChat by replacing linear iteration through _localizedCommands with direct dictionary lookup via GetCommandPrefixByName, and caching the result to avoid duplicate method calls.

  • Replaced O(n) iteration with O(1) dictionary lookup using pre-populated VanillaCommandsPrefixs dictionary
  • Cached commandPrefix result to eliminate redundant GetCommandPrefixByName calls
  • Added null/empty check for args.CommandId._name before lookup
  • Behavior remains identical while significantly improving performance for every chat message using command IDs

Confidence Score: 5/5

  • This PR is safe to merge with no risk
  • Clean performance optimization that replaces inefficient iteration with dictionary lookup, caches results to avoid duplicate calls, and maintains identical behavior with proper null checks
  • No files require special attention

Important Files Changed

Filename Overview
TShockAPI/TShock.cs Replaced O(n) iteration with O(1) dictionary lookup and cached result to avoid duplicate calls

Last reviewed commit: 7d38357

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant