Skip to content

bulk load#57

Open
declanvk wants to merge 1 commit intomainfrom
bulk-load
Open

bulk load#57
declanvk wants to merge 1 commit intomainfrom
bulk-load

Conversation

@declanvk
Copy link
Owner

  • Add split_off fuzz action, update docs and safety condition
  • Implement bulk insert operation

@declanvk declanvk linked an issue Jul 11, 2025 that may be closed by this pull request
@declanvk
Copy link
Owner Author

The benchmark results are not super impressive and I'm seeing sizeable regressions in areas of the code that I thought would be unrelated.

Even for the specific benchmark that should be sped up (bench_split_off) the results show a loss of performance. I'd like to merge into main some more micro-benchmarks for From<[(K, V); N> for TreeMap<K, V, PREFIX_LEN> and the similar FromIterator method, maybe those will show some improvement? Otherwise I'd need to optimize this further before merging (or not merge at all)

iai_callgrind::bench_clone_group::bench_clone with_prefixes:...
  Baselines:                               |ea659cb
  Instructions:                    20347189|20347190             (-0.00000%) [-1.00000x]
  L1 Hits:                         27044952|27044951             (+0.00000%) [+1.00000x]
  LL Hits:                            53229|53231                (-0.00376%) [-1.00004x]
  RAM Hits:                           53907|53907                (No change)
  Total read+write:                27152088|27152089             (-0.00000%) [-1.00000x]
  Estimated Cycles:                29197842|29197851             (-0.00003%) [-1.00000x]
iai_callgrind::bench_clone_group::bench_clone dictionary:...
  Baselines:                               |ea659cb
  Instructions:                    23766804|23836916             (-0.29413%) [-1.00295x]
  L1 Hits:                         31899541|31907113             (-0.02373%) [-1.00024x]
  LL Hits:                            69324|65654                (+5.58991%) [+1.05590x]
  RAM Hits:                           60593|64482                (-6.03114%) [-1.06418x]
  Total read+write:                32029458|32037249             (-0.02432%) [-1.00024x]
  Estimated Cycles:                34366916|34492253             (-0.36338%) [-1.00365x]
iai_callgrind::bench_lookup_group::bench_lookup_single first_key:...
  Baselines:                               |ea659cb
  Instructions:                         153|152                  (+0.65789%) [+1.00658x]
  L1 Hits:                              169|169                  (No change)
  LL Hits:                                8|6                    (+33.3333%) [+1.33333x]
  RAM Hits:                              13|14                   (-7.14286%) [-1.07692x]
  Total read+write:                     190|189                  (+0.52910%) [+1.00529x]
  Estimated Cycles:                     664|689                  (-3.62845%) [-1.03765x]
iai_callgrind::bench_lookup_group::bench_lookup_single last_key:...
  Baselines:                               |ea659cb
  Instructions:                         220|219                  (+0.45662%) [+1.00457x]
  L1 Hits:                              239|249                  (-4.01606%) [-1.04184x]
  LL Hits:                               10|0                    (+++inf+++) [+++inf+++]
  RAM Hits:                              17|16                   (+6.25000%) [+1.06250x]
  Total read+write:                     266|265                  (+0.37736%) [+1.00377x]
  Estimated Cycles:                     884|809                  (+9.27070%) [+1.09271x]
iai_callgrind::bench_lookup_group::bench_lookup_multiple dictionary:...
  Baselines:                               |ea659cb
  Instructions:                      422085|419941               (+0.51055%) [+1.00511x]
  L1 Hits:                           508745|506619               (+0.41964%) [+1.00420x]
  LL Hits:                              724|655                  (+10.5344%) [+1.10534x]
  RAM Hits:                              19|27                   (-29.6296%) [-1.42105x]
  Total read+write:                  509488|507301               (+0.43111%) [+1.00431x]
  Estimated Cycles:                  513030|510839               (+0.42890%) [+1.00429x]
iai_callgrind::bench_remove_group::bench_remove_single first_key:...
  Baselines:                               |ea659cb
  Instructions:                    10915896|10925736             (-0.09006%) [-1.00090x]
  L1 Hits:                         15275454|15287261             (-0.07723%) [-1.00077x]
  LL Hits:                            64528|64618                (-0.13928%) [-1.00139x]
  RAM Hits:                             173|83                   (+108.434%) [+2.08434x]
  Total read+write:                15340155|15351962             (-0.07691%) [-1.00077x]
  Estimated Cycles:                15604149|15613256             (-0.05833%) [-1.00058x]
iai_callgrind::bench_remove_group::bench_remove_single last_key:...
  Baselines:                               |ea659cb
  Instructions:                    10914974|10924799             (-0.08993%) [-1.00090x]
  L1 Hits:                         15274183|15285967             (-0.07709%) [-1.00077x]
  LL Hits:                            64482|64605                (-0.19039%) [-1.00191x]
  RAM Hits:                             195|77                   (+153.247%) [+2.53247x]
  Total read+write:                15338860|15350649             (-0.07680%) [-1.00077x]
  Estimated Cycles:                15603418|15611687             (-0.05297%) [-1.00053x]
iai_callgrind::bench_remove_group::bench_remove_multiple dictionary:...
  Baselines:                               |ea659cb
  Instructions:                    11697185|11347635             (+3.08038%) [+1.03080x]
  L1 Hits:                         16313308|15813566             (+3.16021%) [+1.03160x]
  LL Hits:                            70010|63859                (+9.63216%) [+1.09632x]
  RAM Hits:                            3263|1997                 (+63.3951%) [+1.63395x]
  Total read+write:                16386581|15879422             (+3.19381%) [+1.03194x]
  Estimated Cycles:                16777563|16202756             (+3.54759%) [+1.03548x]
iai_callgrind::bench_insert_group::bench_insert_single first_key:...
  Baselines:                               |ea659cb
  Instructions:                    10916161|10926006             (-0.09011%) [-1.00090x]
  L1 Hits:                         15275892|15287741             (-0.07751%) [-1.00078x]
  LL Hits:                            64487|64614                (-0.19655%) [-1.00197x]
  RAM Hits:                             218|55                   (+296.364%) [+3.96364x]
  Total read+write:                15340597|15352410             (-0.07695%) [-1.00077x]
  Estimated Cycles:                15605957|15612736             (-0.04342%) [-1.00043x]
iai_callgrind::bench_insert_group::bench_insert_single last_key:...
  Baselines:                               |ea659cb
  Instructions:                    10916661|10926506             (-0.09010%) [-1.00090x]
  L1 Hits:                         15276507|15288390             (-0.07773%) [-1.00078x]
  LL Hits:                            64453|64611                (-0.24454%) [-1.00245x]
  RAM Hits:                             284|56                   (+407.143%) [+5.07143x]
  Total read+write:                15341244|15353057             (-0.07694%) [-1.00077x]
  Estimated Cycles:                15608712|15613405             (-0.03006%) [-1.00030x]
iai_callgrind::bench_insert_group::bench_insert_multiple dictionary:...
  Baselines:                               |ea659cb
  Instructions:                    11992039|11991523             (+0.00430%) [+1.00004x]
  L1 Hits:                         16800103|16799370             (+0.00436%) [+1.00004x]
  LL Hits:                            65909|67300                (-2.06686%) [-1.02110x]
  RAM Hits:                            1660|279                  (+494.982%) [+5.94982x]
  Total read+write:                16867672|16866949             (+0.00429%) [+1.00004x]
  Estimated Cycles:                17187748|17145635             (+0.24562%) [+1.00246x]
iai_callgrind::bench_iterator_group::bench_full_iterator dictionary:...
  Baselines:                               |ea659cb
  Instructions:                      196616|196616               (No change)
  L1 Hits:                           202003|196621               (+2.73725%) [+1.02737x]
  LL Hits:                            27385|32768                (-16.4276%) [-1.19657x]
  RAM Hits:                               2|1                    (+100.000%) [+2.00000x]
  Total read+write:                  229390|229390               (No change)
  Estimated Cycles:                  338998|360496               (-5.96345%) [-1.06342x]
iai_callgrind::bench_iterator_group::bench_prefix_iterator empty:...
  Baselines:                               |ea659cb
  Instructions:                      198061|198061               (No change)
  L1 Hits:                           203784|198420               (+2.70336%) [+1.02703x]
  LL Hits:                            27413|32775                (-16.3600%) [-1.19560x]
  RAM Hits:                              25|27                   (-7.40741%) [-1.08000x]
  Total read+write:                  231222|231222               (No change)
  Estimated Cycles:                  341724|363240               (-5.92336%) [-1.06296x]
iai_callgrind::bench_iterator_group::bench_prefix_iterator specific_key:...
  Baselines:                               |ea659cb
  Instructions:                         321|321                  (No change)
  L1 Hits:                              366|373                  (-1.87668%) [-1.01913x]
  LL Hits:                                9|2                    (+350.000%) [+4.50000x]
  RAM Hits:                              27|27                   (No change)
  Total read+write:                     402|402                  (No change)
  Estimated Cycles:                    1356|1328                 (+2.10843%) [+1.02108x]
iai_callgrind::bench_iterator_group::bench_prefix_iterator random_partial:...
  Baselines:                               |ea659cb
  Instructions:                         502|502                  (No change)
  L1 Hits:                              569|570                  (-0.17544%) [-1.00176x]
  LL Hits:                               17|16                   (+6.25000%) [+1.06250x]
  RAM Hits:                              24|24                   (No change)
  Total read+write:                     610|610                  (No change)
  Estimated Cycles:                    1494|1490                 (+0.26846%) [+1.00268x]
iai_callgrind::bench_iterator_group::bench_fuzzy_iterator zero:...
  Baselines:                               |ea659cb
  Instructions:                        5238|4991                 (+4.94891%) [+1.04949x]
  L1 Hits:                             6736|6416                 (+4.98753%) [+1.04988x]
  LL Hits:                               20|4                    (+400.000%) [+5.00000x]
  RAM Hits:                              42|43                   (-2.32558%) [-1.02381x]
  Total read+write:                    6798|6463                 (+5.18335%) [+1.05183x]
  Estimated Cycles:                    8306|7941                 (+4.59640%) [+1.04596x]
iai_callgrind::bench_iterator_group::bench_fuzzy_iterator specific_key:...
  Baselines:                               |ea659cb
  Instructions:                    30653792|30858029             (-0.66186%) [-1.00666x]
  L1 Hits:                         39736612|40257444             (-1.29375%) [-1.01311x]
  LL Hits:                            65330|64564                (+1.18642%) [+1.01186x]
  RAM Hits:                             100|262                  (-61.8321%) [-2.62000x]
  Total read+write:                39802042|40322270             (-1.29018%) [-1.01307x]
  Estimated Cycles:                40066762|40589434             (-1.28770%) [-1.01305x]
iai_callgrind::bench_iterator_group::bench_range_iterator full:...
  Baselines:                               |ea659cb
  Instructions:                      196748|196748               (No change)
  L1 Hits:                           202176|196800               (+2.73171%) [+1.02732x]
  LL Hits:                            27396|32773                (-16.4068%) [-1.19627x]
  RAM Hits:                              12|11                   (+9.09091%) [+1.09091x]
  Total read+write:                  229584|229584               (No change)
  Estimated Cycles:                  339576|361050               (-5.94765%) [-1.06324x]
iai_callgrind::bench_iterator_group::bench_range_iterator specific_key:...
  Baselines:                               |ea659cb
  Instructions:                         936|936                  (No change)
  L1 Hits:                             1110|1109                 (+0.09017%) [+1.00090x]
  LL Hits:                               20|20                   (No change)
  RAM Hits:                              30|31                   (-3.22581%) [-1.03333x]
  Total read+write:                    1160|1160                 (No change)
  Estimated Cycles:                    2260|2294                 (-1.48213%) [-1.01504x]
iai_callgrind::bench_iterator_group::bench_range_iterator middle_third:...
  Baselines:                               |ea659cb
  Instructions:                       66547|66547                (No change)
  L1 Hits:                            68430|66730                (+2.54758%) [+1.02548x]
  LL Hits:                             9254|10953                (-15.5117%) [-1.18360x]
  RAM Hits:                              31|32                   (-3.12500%) [-1.03226x]
  Total read+write:                   77715|77715                (No change)
  Estimated Cycles:                  115785|122615               (-5.57028%) [-1.05899x]
iai_callgrind::bench_modifying_group::bench_retain all:...
  Baselines:                               |ea659cb
  Instructions:                    11079648|11089484             (-0.08870%) [-1.00089x]
  L1 Hits:                         15439231|15451022             (-0.07631%) [-1.00076x]
  LL Hits:                            97319|97387                (-0.06982%) [-1.00070x]
  RAM Hits:                             135|76                   (+77.6316%) [+1.77632x]
  Total read+write:                15536685|15548485             (-0.07589%) [-1.00076x]
  Estimated Cycles:                15930551|15940617             (-0.06315%) [-1.00063x]
iai_callgrind::bench_modifying_group::bench_retain half:...
  Baselines:                               |ea659cb
  Instructions:                    25863253|25855573             (+0.02970%) [+1.00030x]
  L1 Hits:                         34885101|34878596             (+0.01865%) [+1.00019x]
  LL Hits:                           272150|272391               (-0.08848%) [-1.00089x]
  RAM Hits:                             405|247                  (+63.9676%) [+1.63968x]
  Total read+write:                35157656|35151234             (+0.01827%) [+1.00018x]
  Estimated Cycles:                36260026|36249196             (+0.02988%) [+1.00030x]
iai_callgrind::bench_modifying_group::bench_retain none:...
  Baselines:                               |ea659cb
  Instructions:                    29360062|29337238             (+0.07780%) [+1.00078x]
  L1 Hits:                         39629938|39609099             (+0.05261%) [+1.00053x]
  LL Hits:                            65421|65616                (-0.29718%) [-1.00298x]
  RAM Hits:                             356|174                  (+104.598%) [+2.04598x]
  Total read+write:                39695715|39674889             (+0.05249%) [+1.00052x]
  Estimated Cycles:                39969503|39943269             (+0.06568%) [+1.00066x]
iai_callgrind::bench_modifying_group::bench_append no_overlap:...
  Baselines:                               |ea659cb
  Instructions:                     1955842|1957133              (-0.06596%) [-1.00066x]
  L1 Hits:                          2728244|2726415              (+0.06708%) [+1.00067x]
  LL Hits:                             5928|5648                 (+4.95751%) [+1.04958x]
  RAM Hits:                             264|891                  (-70.3704%) [-3.37500x]
  Total read+write:                 2734436|2732954              (+0.05423%) [+1.00054x]
  Estimated Cycles:                 2767124|2785840              (-0.67183%) [-1.00676x]
iai_callgrind::bench_modifying_group::bench_append overlap:...
  Baselines:                               |ea659cb
  Instructions:                     1569028|1570831              (-0.11478%) [-1.00115x]
  L1 Hits:                          2209377|2208786              (+0.02676%) [+1.00027x]
  LL Hits:                             6135|5131                 (+19.5673%) [+1.19567x]
  RAM Hits:                             270|895                  (-69.8324%) [-3.31481x]
  Total read+write:                 2215782|2214812              (+0.04380%) [+1.00044x]
  Estimated Cycles:                 2249502|2265766              (-0.71781%) [-1.00723x]
iai_callgrind::bench_modifying_group::bench_split_off dictionary:...
  Baselines:                               |ea659cb
  Instructions:                    38347995|36077100             (+6.29456%) [+1.06295x]
  L1 Hits:                         53015088|49111515             (+7.94839%) [+1.07948x]
  LL Hits:                           400451|91413                (+338.068%) [+4.38068x]
  RAM Hits:                           11531|744                  (+1449.87%) [+15.4987x]
  Total read+write:                53427070|49203672             (+8.58350%) [+1.08584x]
  Estimated Cycles:                55420928|49594620             (+11.7479%) [+1.11748x]
iai_callgrind::bench_modifying_group::bench_extract_if all:...
  Baselines:                               |ea659cb
  Instructions:                    36172157|36227610             (-0.15307%) [-1.00153x]
  L1 Hits:                         49289583|49414686             (-0.25317%) [-1.00254x]
  LL Hits:                           268417|268996               (-0.21524%) [-1.00216x]
  RAM Hits:                           11131|13023                (-14.5281%) [-1.16998x]
  Total read+write:                49569131|49696705             (-0.25671%) [-1.00257x]
  Estimated Cycles:                51021253|51215471             (-0.37922%) [-1.00381x]
iai_callgrind::bench_modifying_group::bench_extract_if half:...
  Baselines:                               |ea659cb
  Instructions:                    26443419|26524337             (-0.30507%) [-1.00306x]
  L1 Hits:                         35635404|35786439             (-0.42205%) [-1.00424x]
  LL Hits:                           319197|320314               (-0.34872%) [-1.00350x]
  RAM Hits:                            5165|6856                 (-24.6645%) [-1.32740x]
  Total read+write:                35959766|36113609             (-0.42600%) [-1.00428x]
  Estimated Cycles:                37412164|37627969             (-0.57352%) [-1.00577x]
iai_callgrind::bench_modifying_group::bench_extract_if none:...
  Baselines:                               |ea659cb
  Instructions:                    11112446|11122284             (-0.08845%) [-1.00089x]
  L1 Hits:                         15504812|15516603             (-0.07599%) [-1.00076x]
  LL Hits:                            97320|97386                (-0.06777%) [-1.00068x]
  RAM Hits:                             141|82                   (+71.9512%) [+1.71951x]
  Total read+write:                15602273|15614071             (-0.07556%) [-1.00076x]
  Estimated Cycles:                15996347|16006403             (-0.06282%) [-1.00063x]

Iai-Callgrind result: Ok. 29 without regressions; 0 regressed; 29 benchmarks finished in 38.8227s

@declanvk declanvk force-pushed the bulk-load branch 2 times, most recently from bde066f to 728ee8b Compare July 16, 2025 18:19
**Description**
 - Add a bulk insert operation that can take a list of key-value pairs
   and create a tree structure by recursively bucketing them based on
   key bytes
 - Add helper functions for creating portions of the tree with
   uninitialized key-value pairs in the leafs, and being able to later
   initialized them.
 - Update several `TreeMap` APIs to use the bulk insert method.

**Motivation**
My hope is that the bulk insert operation will be more effecient when
compared to a "one at a time" insert strategy. Initial benchmarking says
that it may need some additional work.

**Testing Done**
`./scripts/full-test.sh nightly` and ran fuzzer for 1 hour. Added unit
tests too.
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.

Implement bulk insert on create

1 participant