Multi-Colors icon indicating copy to clipboard operation
Multi-Colors copied to clipboard

perf(morecolors): low-level hashtable optimization

Open Rushaway opened this issue 5 months ago • 1 comments

Performance Optimization: Low-Level Hashtable Implementation (See benchs)

Overview

Replace high-level StringMap with optimized low-level Hashtable implementation, achieving 12-50% performance improvements through direct memory control and custom hash functions.

Technical Changes

  • Migrated from StringMap to direct Hashtable operations
  • Implemented custom hash functions optimized for color name patterns
  • Manual memory management for optimal cache locality
  • Eliminated API abstraction overhead
  • Early skip for Observers prints
  • Cache current engine value
  • Remove regex

Performance Results

  • Average improvement: ~37% faster execution
  • Best case: 49.66% improvement (CRemoveTags)
  • Consistent gains: All functions benefit from reduced overhead

Benefits

  • ✅ Direct hash table control for maximum performance
  • ✅ Custom hash functions tuned for color lookup patterns
  • ✅ Eliminated high-level API overhead
  • ✅ Better memory utilization and cache performance
  • ✅ Maintained full compatibility

✅ Summary

  • Rushaway version is faster in every function compared to the original.
  • Performance gains range from ~12% to ~50%, depending on the function.

🧪 Benchmark Comparison — Rushaway vs Original

📊 Table: Execution Time & Performance Gains

Function 🧾 Original ⚡ Rushaway 🚀 Gain (%) ⚡ Faster
CPrintToChat 0.003518 0.002149 -38.93% faster Rushaway
CPrintToChatAll 0.066624 0.036293 -45.52% faster Rushaway
CPrintToChatEx 0.003184 0.002015 -36.73% faster Rushaway
CPrintToChatAllEx 0.068966 0.043021 -37.62% faster Rushaway
CReplyToCommand 0.003093 0.001757 -43.17% faster Rushaway
CReplyToCommandEx 0.003207 0.002069 -35.46% faster Rushaway
CShowActivity 0.004377 0.003001 -31.45% faster Rushaway
CShowActivityEx 0.005665 0.003610 -36.27% faster Rushaway
CShowActivity2 0.004767 0.003003 -37.02% faster Rushaway
CPrintToServer 0.005295 0.003458 -34.69% faster Rushaway
CFormatColor 0.002297 0.001184 -48.45% faster Rushaway
CRemoveTags 0.002065 0.001040 -49.66% faster Rushaway
CSetPrefix/CClearPrefix 0.000082 0.000072 -12.20% faster Rushaway

🏅 Functions Ranked by Performance Gain (Rushaway vs Original)

Rank Function 🧾 Original ⚡ Rushaway 🚀 Gain (%)
1 CRemoveTags 0.002065 0.001040 -49.66% faster
2 CFormatColor 0.002297 0.001184 -48.45% faster
3 CPrintToChatAll 0.066624 0.036293 -45.52% faster
4 CReplyToCommand 0.003093 0.001757 -43.17% faster
5 CPrintToChat 0.003518 0.002149 -38.93% faster
6 CPrintToChatAllEx 0.068966 0.043021 -37.62% faster
7 CShowActivity2 0.004767 0.003003 -37.02% faster
8 CPrintToChatEx 0.003184 0.002015 -36.73% faster
9 CShowActivityEx 0.005665 0.003610 -36.27% faster
10 CReplyToCommandEx 0.003207 0.002069 -35.46% faster
11 CPrintToServer 0.005295 0.003458 -34.69% faster
12 CShowActivity 0.004377 0.003001 -31.45% faster
13 CSetPrefix/CClearPrefix 0.000082 0.000072 -12.20% faster

📄 Benchmark/Test plugin used for testing performance: https://gist.github.com/Rushaway/0e2e9557d490976367d16ede77413521

Rushaway avatar Aug 28 '25 07:08 Rushaway