Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: BTreeMap V2 (beta) #115

Merged
merged 8 commits into from
Sep 5, 2023
Merged

feat: BTreeMap V2 (beta) #115

merged 8 commits into from
Sep 5, 2023

Conversation

ielashi
Copy link
Contributor

@ielashi ielashi commented Aug 22, 2023

This commit introduces V2 of BTreeMap which supports unbounded keys and values.

  • V2 so far is intended only for beta testing and should not be used in any production setting. By default, BTreeMaps are using V1. V2 nodes are available only when initializing a BTreeMap with init_v2 or new_v2. In the future, V1 maps will be migrated automatically to V2.
  • Tests are updated to run for both V1 and V2 versions of the map.
  • Benchmarks now include both V1 and V2. V2 is significantly slower at the moment per the benchmarking results below, but optimizations to follow on this PR will narrow that gap.
btreemap_insert_blob_4_1024
                        time:   [914.81 M Instructions 914.81 M Instructions 914.81 M Instructions]
                        change: [+0.1085% +0.1085% +0.1085%] (p = 0.00 < 0.05)
                        Change within noise threshold.

btreemap_insert_blob_4_1024_v2
                        time:   [5074.9 M Instructions 5074.9 M Instructions 5074.9 M Instructions]
                        change: [+0.0000% +0.0000% +0.0000%] (p = NaN > 0.05)
                        No change in performance detected.

btreemap_insert_blob_8_1024
                        time:   [1054.3 M Instructions 1054.3 M Instructions 1054.3 M Instructions]
                        change: [+0.1306% +0.1306% +0.1306%] (p = 0.00 < 0.05)
                        Change within noise threshold.

btreemap_insert_blob_8_1024_v2
                        time:   [5533.1 M Instructions 5533.1 M Instructions 5533.1 M Instructions]
                        change: [+0.0000% +0.0000% +0.0000%] (p = NaN > 0.05)
                        No change in performance detected.

btreemap_insert_blob_16_1024
                        time:   [1150.9 M Instructions 1150.9 M Instructions 1150.9 M Instructions]
                        change: [+0.1327% +0.1327% +0.1327%] (p = 0.00 < 0.05)
                        Change within noise threshold.

btreemap_insert_blob_16_1024_v2
                        time:   [5638.8 M Instructions 5638.8 M Instructions 5638.8 M Instructions]
                        change: [+0.0000% +0.0000% +0.0000%] (p = NaN > 0.05)
                        No change in performance detected.

btreemap_insert_blob_32_1024
                        time:   [1194.9 M Instructions 1194.9 M Instructions 1194.9 M Instructions]
                        change: [+0.1312% +0.1312% +0.1312%] (p = 0.00 < 0.05)
                        Change within noise threshold.

btreemap_insert_blob_32_1024_v2
                        time:   [5813.9 M Instructions 5813.9 M Instructions 5813.9 M Instructions]
                        change: [+0.0000% +0.0000% +0.0000%] (p = NaN > 0.05)
                        No change in performance detected.

btreemap_insert_blob_64_1024
                        time:   [1434.8 M Instructions 1434.8 M Instructions 1434.8 M Instructions]
                        change: [+0.1131% +0.1131% +0.1131%] (p = 0.00 < 0.05)
                        Change within noise threshold.

btreemap_insert_blob_64_1024_v2
                        time:   [6414.8 M Instructions 6414.8 M Instructions 6414.8 M Instructions]
                        change: [+0.0000% +0.0000% +0.0000%] (p = NaN > 0.05)
                        No change in performance detected.

btreemap_insert_blob_128_1024
                        time:   [1694.4 M Instructions 1694.4 M Instructions 1694.4 M Instructions]
                        change: [+0.0955% +0.0955% +0.0955%] (p = 0.00 < 0.05)
                        Change within noise threshold.

btreemap_insert_blob_128_1024_v2
                        time:   [7011.3 M Instructions 7011.3 M Instructions 7011.3 M Instructions]
                        change: [+0.0000% +0.0000% +0.0000%] (p = NaN > 0.05)
                        No change in performance detected.

btreemap_insert_blob_256_1024
                        time:   [2211.4 M Instructions 2211.4 M Instructions 2211.4 M Instructions]
                        change: [+0.0733% +0.0733% +0.0733%] (p = 0.00 < 0.05)
                        Change within noise threshold.

btreemap_insert_blob_256_1024_v2
                        time:   [7715.7 M Instructions 7715.7 M Instructions 7715.7 M Instructions]
                        change: [+0.0000% +0.0000% +0.0000%] (p = NaN > 0.05)
                        No change in performance detected.

btreemap_insert_blob_512_1024
                        time:   [3272.6 M Instructions 3272.6 M Instructions 3272.6 M Instructions]
                        change: [+0.0501% +0.0501% +0.0501%] (p = 0.00 < 0.05)
                        Change within noise threshold.

btreemap_insert_blob_512_1024_v2
                        time:   [9668.8 M Instructions 9668.8 M Instructions 9668.8 M Instructions]
                        change: [+0.0000% +0.0000% +0.0000%] (p = NaN > 0.05)
                        No change in performance detected.

btreemap_insert_u64_u64 time:   [771.21 M Instructions 771.21 M Instructions 771.21 M Instructions]
                        change: [+0.1894% +0.1894% +0.1894%] (p = 0.00 < 0.05)
                        Change within noise threshold.

btreemap_insert_u64_u64_v2
                        time:   [1187.0 M Instructions 1187.0 M Instructions 1187.0 M Instructions]
                        change: [+0.0000% +0.0000% +0.0000%] (p = NaN > 0.05)
                        No change in performance detected.

btreemap_insert_u64_blob_8
                        time:   [744.40 M Instructions 744.40 M Instructions 744.40 M Instructions]
                        change: [+0.2643% +0.2643% +0.2643%] (p = 0.00 < 0.05)
                        Change within noise threshold.

btreemap_insert_u64_blob_8_v2
                        time:   [1123.4 M Instructions 1123.4 M Instructions 1123.4 M Instructions]
                        change: [+0.0000% +0.0000% +0.0000%] (p = NaN > 0.05)
                        No change in performance detected.

btreemap_insert_blob_8_u64
                        time:   [655.21 M Instructions 655.21 M Instructions 655.21 M Instructions]
                        change: [+0.1334% +0.1334% +0.1334%] (p = 0.00 < 0.05)
                        Change within noise threshold.

btreemap_insert_blob_8_u64_v2
                        time:   [1091.2 M Instructions 1091.2 M Instructions 1091.2 M Instructions]
                        change: [+0.0000% +0.0000% +0.0000%] (p = NaN > 0.05)
                        No change in performance detected.

btreemap_get_blob_4_1024
                        time:   [401.24 M Instructions 401.24 M Instructions 401.24 M Instructions]
                        change: [+0.2791% +0.2791% +0.2791%] (p = 0.00 < 0.05)
                        Change within noise threshold.

btreemap_get_blob_4_1024_v2
                        time:   [4919.7 M Instructions 4919.7 M Instructions 4919.7 M Instructions]
                        change: [+0.0000% +0.0000% +0.0000%] (p = NaN > 0.05)
                        No change in performance detected.

btreemap_get_blob_8_1024
                        time:   [468.41 M Instructions 468.41 M Instructions 468.41 M Instructions]
                        change: [+0.3022% +0.3022% +0.3022%] (p = 0.00 < 0.05)
                        Change within noise threshold.

btreemap_get_blob_8_1024_v2
                        time:   [4541.9 M Instructions 4541.9 M Instructions 4541.9 M Instructions]
                        change: [+0.0000% +0.0000% +0.0000%] (p = NaN > 0.05)
                        No change in performance detected.

btreemap_get_blob_16_1024
                        time:   [550.95 M Instructions 550.95 M Instructions 550.95 M Instructions]
                        change: [+0.2571% +0.2571% +0.2571%] (p = 0.00 < 0.05)
                        Change within noise threshold.

btreemap_get_blob_16_1024_v2
                        time:   [4599.1 M Instructions 4599.1 M Instructions 4599.1 M Instructions]
                        change: [+0.0000% +0.0000% +0.0000%] (p = NaN > 0.05)
                        No change in performance detected.

btreemap_get_blob_32_1024
                        time:   [581.65 M Instructions 581.65 M Instructions 581.65 M Instructions]
                        change: [+0.2433% +0.2433% +0.2433%] (p = 0.00 < 0.05)
                        Change within noise threshold.

btreemap_get_blob_32_1024_v2
                        time:   [5042.3 M Instructions 5042.3 M Instructions 5042.3 M Instructions]
                        change: [+0.0000% +0.0000% +0.0000%] (p = NaN > 0.05)
                        No change in performance detected.

btreemap_get_blob_64_1024
                        time:   [805.48 M Instructions 805.48 M Instructions 805.48 M Instructions]
                        change: [+0.1756% +0.1756% +0.1756%] (p = 0.00 < 0.05)
                        Change within noise threshold.

btreemap_get_blob_64_1024_v2
                        time:   [5444.2 M Instructions 5444.2 M Instructions 5444.2 M Instructions]
                        change: [+0.0000% +0.0000% +0.0000%] (p = NaN > 0.05)
                        No change in performance detected.

btreemap_get_blob_128_1024
                        time:   [1027.1 M Instructions 1027.1 M Instructions 1027.1 M Instructions]
                        change: [+0.1376% +0.1376% +0.1376%] (p = 0.00 < 0.05)
                        Change within noise threshold.

btreemap_get_blob_128_1024_v2
                        time:   [5956.1 M Instructions 5956.1 M Instructions 5956.1 M Instructions]
                        change: [+0.0000% +0.0000% +0.0000%] (p = NaN > 0.05)
                        No change in performance detected.

btreemap_get_u64_u64    time:   [398.59 M Instructions 398.59 M Instructions 398.59 M Instructions]
                        change: [+0.1511% +0.1511% +0.1511%] (p = 0.00 < 0.05)
                        Change within noise threshold.

btreemap_get_u64_u64_v2 time:   [873.64 M Instructions 873.64 M Instructions 873.64 M Instructions]
                        change: [+0.0000% +0.0000% +0.0000%] (p = NaN > 0.05)
                        No change in performance detected.

btreemap_get_u64_blob_8 time:   [394.74 M Instructions 394.74 M Instructions 394.74 M Instructions]
                        change: [+0.1526% +0.1526% +0.1526%] (p = 0.00 < 0.05)
                        Change within noise threshold.

btreemap_get_u64_blob_8_v2
                        time:   [826.19 M Instructions 826.19 M Instructions 826.19 M Instructions]
                        change: [+0.0000% +0.0000% +0.0000%] (p = NaN > 0.05)
                        No change in performance detected.

btreemap_get_blob_8_u64 time:   [413.86 M Instructions 413.86 M Instructions 413.86 M Instructions]
                        change: [+0.3417% +0.3417% +0.3417%] (p = 0.00 < 0.05)
                        Change within noise threshold.

btreemap_get_blob_8_u64_v2
                        time:   [939.20 M Instructions 939.20 M Instructions 939.20 M Instructions]
                        change: [+0.0000% +0.0000% +0.0000%] (p = NaN > 0.05)
                        No change in performance detected.

btreemap_get_blob_256_1024
                        time:   [1516.9 M Instructions 1516.9 M Instructions 1516.9 M Instructions]
                        change: [+0.0931% +0.0931% +0.0931%] (p = 0.00 < 0.05)
                        Change within noise threshold.

btreemap_get_blob_256_1024_v2
                        time:   [6626.5 M Instructions 6626.5 M Instructions 6626.5 M Instructions]
                        change: [+0.0000% +0.0000% +0.0000%] (p = NaN > 0.05)
                        No change in performance detected.

btreemap_get_blob_512_1024
                        time:   [2482.5 M Instructions 2482.5 M Instructions 2482.5 M Instructions]
                        change: [+0.0569% +0.0569% +0.0569%] (p = 0.00 < 0.05)
                        Change within noise threshold.

btreemap_get_blob_512_1024_v2
                        time:   [8287.2 M Instructions 8287.2 M Instructions 8287.2 M Instructions]
                        change: [+0.0000% +0.0000% +0.0000%] (p = NaN > 0.05)
                        No change in performance detected.

btreemap_remove_blob_4_1024
                        time:   [992.32 M Instructions 992.32 M Instructions 992.32 M Instructions]
                        change: [+0.2592% +0.2592% +0.2592%] (p = 0.00 < 0.05)
                        Change within noise threshold.

btreemap_remove_blob_4_1024_v2
                        time:   [992.32 M Instructions 992.32 M Instructions 992.32 M Instructions]
                        change: [+0.0000% +0.0000% +0.0000%] (p = NaN > 0.05)
                        No change in performance detected.

btreemap_remove_blob_8_1024
                        time:   [1270.9 M Instructions 1270.9 M Instructions 1270.9 M Instructions]
                        change: [+0.2561% +0.2561% +0.2561%] (p = 0.00 < 0.05)
                        Change within noise threshold.

btreemap_remove_blob_8_1024_v2
                        time:   [1270.9 M Instructions 1270.9 M Instructions 1270.9 M Instructions]
                        change: [+0.0000% +0.0000% +0.0000%] (p = NaN > 0.05)
                        No change in performance detected.

btreemap_remove_blob_16_1024
                        time:   [1515.7 M Instructions 1515.7 M Instructions 1515.7 M Instructions]
                        change: [+0.2385% +0.2385% +0.2385%] (p = 0.00 < 0.05)
                        Change within noise threshold.

btreemap_remove_blob_16_1024_v2
                        time:   [6992.4 M Instructions 6992.4 M Instructions 6992.4 M Instructions]
                        change: [+0.0000% +0.0000% +0.0000%] (p = NaN > 0.05)
                        No change in performance detected.

btreemap_remove_blob_32_1024
                        time:   [1591.1 M Instructions 1591.1 M Instructions 1591.1 M Instructions]
                        change: [+0.2333% +0.2333% +0.2333%] (p = 0.00 < 0.05)
                        Change within noise threshold.

btreemap_remove_blob_32_1024_v2
                        time:   [7302.3 M Instructions 7302.3 M Instructions 7302.3 M Instructions]

btreemap_remove_blob_64_1024
                        time:   [1885.5 M Instructions 1885.5 M Instructions 1885.5 M Instructions]
                        change: [+0.2106% +0.2106% +0.2106%] (p = 0.00 < 0.05)
                        Change within noise threshold.

btreemap_remove_blob_64_1024_v2
                        time:   [7648.3 M Instructions 7648.3 M Instructions 7648.3 M Instructions]

btreemap_remove_blob_128_1024
                        time:   [2208.4 M Instructions 2208.4 M Instructions 2208.4 M Instructions]
                        change: [+0.1834% +0.1834% +0.1834%] (p = 0.00 < 0.05)
                        Change within noise threshold.

btreemap_remove_blob_128_1024_v2
                        time:   [8196.6 M Instructions 8196.6 M Instructions 8196.6 M Instructions]

btreemap_remove_blob_256_1024
                        time:   [2817.9 M Instructions 2817.9 M Instructions 2817.9 M Instructions]
                        change: [+0.1411% +0.1411% +0.1411%] (p = 0.00 < 0.05)
                        Change within noise threshold.

btreemap_remove_blob_256_1024_v2
                        time:   [9505.1 M Instructions 9505.1 M Instructions 9505.1 M Instructions]

btreemap_remove_blob_512_1024
                        time:   [4114.4 M Instructions 4114.4 M Instructions 4114.4 M Instructions]
                        change: [+0.0992% +0.0992% +0.0992%] (p = 0.00 < 0.05)
                        Change within noise threshold.

btreemap_remove_blob_512_1024_v2
                        time:   [11.583 B Instructions 11.583 B Instructions 11.583 B Instructions]

btreemap_remove_u64_u64 time:   [1094.6 M Instructions 1094.6 M Instructions 1094.6 M Instructions]
                        change: [+0.2506% +0.2506% +0.2506%] (p = 0.00 < 0.05)
                        Change within noise threshold.

btreemap_remove_u64_u64_v2
                        time:   [1486.5 M Instructions 1486.5 M Instructions 1486.5 M Instructions]

btreemap_remove_u64_blob_8
                        time:   [1053.1 M Instructions 1053.1 M Instructions 1053.1 M Instructions]
                        change: [+0.2572% +0.2572% +0.2572%] (p = 0.00 < 0.05)
                        Change within noise threshold.

btreemap_remove_u64_blob_8_v2
                        time:   [1411.6 M Instructions 1411.6 M Instructions 1411.6 M Instructions]

btreemap_remove_blob_8_u64
                        time:   [868.16 M Instructions 868.16 M Instructions 868.16 M Instructions]
                        change: [+0.3910% +0.3910% +0.3910%] (p = 0.00 < 0.05)
                        Change within noise threshold.

btreemap_remove_blob_8_u64_v2
                        time:   [1346.4 M Instructions 1346.4 M Instructions 1346.4 M Instructions]

@ielashi ielashi marked this pull request as ready for review August 22, 2023 11:28
@ielashi ielashi requested review from roman-kashitsyn and a team as code owners August 22, 2023 11:28
@ielashi ielashi changed the title feat: BTreeMap v2 beta feat: BTreeMap V2 (beta) Aug 22, 2023
Hi @ielashi,

I'm not sure but, is it possible that the init of a new `BTreeMap::new`
in `init_v2` is incorrect in your PR and should be replaced with
`BTreeMap::new_v2`?

At least, while testing your PR, I was facing following error which
seems to be resolved by tweaking those.

> 2023-08-26 14:42:36.677876 UTC: [Canister by6od-j4aaa-aaaaa-qaadq-cai]
Panicked at 'Cannot get max size of unbounded type.',
/Users/daviddalbusco/.cargo/git/checkouts/stable-structures-10185dfe005f3b12/8620b4f/src/storable.rs:450:9
src/btreemap.rs Outdated Show resolved Hide resolved
src/btreemap.rs Outdated Show resolved Hide resolved
src/btreemap.rs Show resolved Hide resolved
src/btreemap.rs Show resolved Hide resolved
src/btreemap.rs Outdated Show resolved Hide resolved
src/btreemap.rs Outdated Show resolved Hide resolved
src/btreemap.rs Show resolved Hide resolved
src/btreemap.rs Outdated Show resolved Hide resolved
src/btreemap.rs Outdated Show resolved Hide resolved
src/btreemap.rs Show resolved Hide resolved
@ielashi
Copy link
Contributor Author

ielashi commented Sep 4, 2023

@dragoljub-duric Thanks for your comments. Tip (for this and future PRs): I'd suggest not blocking the approval of the PR with your comments, since the comments are not related to this particular change. Your comments relate to the existing tests, which the current PR doesn't modify. I'll address your comments, but I wouldn't block approving the PR on them.

@ielashi ielashi enabled auto-merge (squash) September 5, 2023 08:31
@ielashi ielashi enabled auto-merge (squash) September 5, 2023 08:31
@ielashi ielashi merged commit 4a454eb into main Sep 5, 2023
3 checks passed
@ielashi ielashi deleted the ielashi/btree_v2 branch September 5, 2023 08:39
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.

3 participants