Skip to content

optimize Map to achieve first place in the benchmark#1

Merged
llxisdsh merged 4 commits intomainfrom
intHashOpt
Mar 8, 2026
Merged

optimize Map to achieve first place in the benchmark#1
llxisdsh merged 4 commits intomainfrom
intHashOpt

Conversation

@llxisdsh
Copy link
Owner

@llxisdsh llxisdsh commented Mar 8, 2026

  • Optimize integer key hashing
  • Optimize Map to achieve first place in the benchmark

Summary by CodeRabbit

  • New Features

    • Added explicit Delete() method for removing keys from FlatMap.
  • Performance

    • Optimized integer-key hashing paths for improved lookup and operation speed.
    • Refined internal compute and load operations for better efficiency.
  • Tests

    • Updated test utilities to reflect new internal optimization patterns.

@coderabbitai
Copy link

coderabbitai bot commented Mar 8, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This PR introduces an integer-key optimization path to Map and FlatMap concurrent collections, refactors internal compute methods to use flag-based control flow, adds a Delete method to FlatMap, updates the default hasher signature to return an intKey indicator, and adds hashing utilities for integer keys.

Changes

Cohort / File(s) Summary
Hash Infrastructure & Utilities
map_util.go
Extended defaultHasher signature to return three values including an intKey boolean flag. Added intHash generic function and h1IntKey helper for integer-key hash paths. Introduced compute flag constants (computeInit, computeIgnoreHint, computeSkipIfFound, computeSkipIfNotFound) replacing prior enableFastPath constant.
Core Map Implementation
map.go
Added intKey field to Map struct. Updated Load path to support integer-key hashing branches. Introduced new computeV2_ method implementing unified fast/slow-path logic. Refactored computeEntry_ signature to accept flags instead of multiple parameters. Updated public methods (LoadOrStore, LoadAndUpdate, LoadAndDelete, Store, Delete, Compute, CloneTo) to route through new flag-based compute paths. Adjusted copy/resize logic to handle intKey state propagation.
Core FlatMap Implementation
flat_map.go
Added intKey field to FlatMap struct. Added public Delete method for explicit key removal. Updated Load and compute paths to branch on intKey for integer-key hash function usage. Reworked internal compute flows to use new computeV2_ style with flags for init and fast-path handling. Adjusted bucket copy/resize logic to compute and propagate h1v for integer keys during rehashing.
Compute Delegation
map_rebuild.go
Updated Compute method to delegate to internal compute with pointer-based key argument and combined flag set (computeInit|computeIgnoreHint) instead of previous boolean pattern.
Tests
map_test.go
Removed TestMap_HashUint64On32Bit test. Updated TestMap_DefaultHasherEdgeCases to handle defaultHasher returning three values instead of two.
Benchmarks
benchmark/map_throughput_test.go
Simplified testInsert_cc_FlatMap and testInsert_cc_Map by removing active Compute blocks and using Store-only patterns per iteration.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Poem

🐰 With integer keys we hop so fast,
New flags guide us through the paths,
Delete arrives to free the load,
Compute refactored down the road,
Optimization speeds our way! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main objective of the changeset: optimizing the Map implementation to achieve better benchmark performance through integer key hashing optimization.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch intHashOpt

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@llxisdsh llxisdsh merged commit c934dca into main Mar 8, 2026
4 of 5 checks passed
@llxisdsh llxisdsh deleted the intHashOpt branch March 8, 2026 12:04
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