Optimize GEORADIUS command performance with pre-allocated buffer
Description
- The GEORADIUS command stores searched map points in geoArray, which triggers at least two memory allocations: one for the
geoArraycreation and another for eachgeoPointinitialization. - We can reduce these two memory allocations:
- converting
geoArrayfrom a heap-allocated variable to a stack-allocated one - embedding
geoPointdirectly within geoArray
- converting
Benchmark Run the benchmark command five times with the command below, and take the peak value as the final result.
for((x=0;x<5;x+=1)); do valkey-cli flushall; valkey-benchmark -r $POINTS_SIZE geoadd key 100 70 l__rand_int__; valkey-benchmark -P 2 -n 10000000 georadius key 100 70 300 km; done
| $POINTS_SIZE | QPS before optimization | QPS after optimization | Performance Boost |
|---|---|---|---|
| 1 | 430015.06 | 436585.88 | 1.5% |
| 4 | 381766.81 | 386279.34 | 1.2% |
| 16 | 264592.28 | 268391.53 | 1.4% |
| 64 | 120035.05 | 120277.60 | 0.2% |
CPU: AMD EPYC 9K65 192-Core Processor* 8 OS: Ubuntu Server 24.04 LTS 64bit Memory: 32GB VM: Tencent cloud SA9 | SA9.2XLARGE32
Codecov Report
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 71.23%. Comparing base (
1531b44) to head (b64df52). Report is 15 commits behind head on unstable.
Additional details and impacted files
@@ Coverage Diff @@
## unstable #2116 +/- ##
============================================
- Coverage 71.24% 71.23% -0.02%
============================================
Files 122 122
Lines 66030 66049 +19
============================================
+ Hits 47045 47051 +6
- Misses 18985 18998 +13
| Files with missing lines | Coverage Δ | |
|---|---|---|
| src/geo.c | 93.62% <100.00%> (+0.04%) |
:arrow_up: |
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
@KarthikSubbarao you know the geo code. PTAL.