perf: optimize _peer_to_session from std::map to std::unordered_map
Description
Replace std::map with std::unordered_map for _peer_to_session to achieve O(1) lookup performance instead of O(log n).
The peer_t type (ENetPeer*) is a pointer, which has native hash support. All operations (find, emplace, erase) are interface-compatible between std::map and std::unordered_map.
This change aligns with the code comment at line 529 which states: 'Insert this into the map for O(1) lookups in the future'
Tested:
- Interface compatibility verified with unit test
- Performance benchmark confirms expected improvements
- No API changes required (drop-in replacement)
Screenshot
N/A - This is a performance optimization with no UI changes.
Issues Fixed or Closed
N/A - This addresses a performance optimization opportunity identified through code analysis.
Roadmap Issues
N/A
Type of Change
- [ ] feat: New feature (non-breaking change which adds functionality)
- [ ] fix: Bug fix (non-breaking change which fixes an issue)
- [ ] docs: Documentation only changes
- [ ] style: Changes that do not affect the meaning of the code (white-space, formatting, missing semicolons, etc.)
- [ ] refactor: Code change that neither fixes a bug nor adds a feature
- [x] perf: Code change that improves performance
- [ ] test: Adding missing tests or correcting existing tests
- [ ] build: Changes that affect the build system or external dependencies
- [ ] ci: Changes to CI configuration files and scripts
- [ ] chore: Other changes that don't modify src or test files
- [ ] revert: Reverts a previous commit
- [ ] BREAKING CHANGE: Introduces a breaking change (can be combined with any type above)
Checklist
- [x] Code follows the style guidelines of this project
- [x] Code has been self-reviewed
- [ ] Code has been commented, particularly in hard-to-understand areas
- [ ] Code docstring/documentation-blocks for new or existing methods/components have been added or updated
- [ ] Unit tests have been added or updated for any new or modified functionality
AI Usage
- [ ] None: No AI tools were used in creating this PR
- [x] Light: AI provided minor assistance (formatting, simple suggestions)
- [ ] Moderate: AI helped with code generation or debugging specific parts
- [ ] Heavy: AI generated most or all of the code changes
Quality Gate passed
Issues
0 New issues
0 Accepted issues
Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 14.22%. Comparing base (1d6d916) to head (8934dd1).
:warning: Report is 2 commits behind head on master.
:white_check_mark: All tests successful. No failed tests found.
Additional details and impacted files
@@ Coverage Diff @@
## master #4415 +/- ##
==========================================
- Coverage 14.94% 14.22% -0.73%
==========================================
Files 63 89 +26
Lines 13726 18936 +5210
Branches 6476 8677 +2201
==========================================
+ Hits 2052 2694 +642
- Misses 8686 15085 +6399
+ Partials 2988 1157 -1831
| Flag | Coverage Δ | |
|---|---|---|
| FreeBSD-14.3-aarch64 | ? |
|
| FreeBSD-14.3-amd64 | 13.55% <ø> (+<0.01%) |
:arrow_up: |
| Linux-AppImage | 11.55% <ø> (-0.02%) |
:arrow_down: |
| Windows-AMD64 | 13.34% <ø> (?) |
Flags with carried forward coverage won't be shown. Click here to find out more.
| Files with missing lines | Coverage Δ | |
|---|---|---|
| src/stream.cpp | 2.84% <ø> (ø) |
|
| src/utility.h | 61.35% <ø> (+2.00%) |
:arrow_up: |