Skip to content

test: improve BTreeMap bench coverage and readability #285

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

Merged
merged 59 commits into from
May 19, 2025
Merged

Conversation

maksymar
Copy link
Contributor

@maksymar maksymar commented Apr 22, 2025

This PR refactors BTreeMap benchmarks to increase coverage and improve readability.

Current benchmark setup has some challenges:

  • does not cover some essential parts, like unbounded types
  • does not scale well when new tests need to be added
    • tests are written individually which increases boilerplate and it's easy to miss a typo

New benchmark setup:

  • removes all V1 benchmarks (everyone should use V2 and as long as V1 works correctly we don't need to track performance changes)
  • covers unbounded types (via FixedVec for v2)
  • improves scalability & readability by using macros for grouping similar tests
    • tests are close to each other for better readability
    • they can be easily copy-pasted without much boilerplate
    • easier to check for typos

Still adding new benchmarks must be handled with care because pocket_ic has a limitation on the number of tests (10k) and the total length of test names (20k chars). This limit is going to be increased soon.

Getting closer to this limit increases running time up to 7 minutes and increases significantly the size of canbench report, which is currently is not very readable.

Current setup supports:

  • bounded / unbounded types
  • each key/value related API is checked against the same grid
  • checked APIs: insert, remove, get, contains, pop_first, pop_last, scan items consequently

CSV report in google sheets.

Copy link

github-actions bot commented Apr 22, 2025

canbench 🏋 (dir: .) 7fc5864 2025-05-19 10:06:09 UTC

./canbench_results.yml is up to date
📦 canbench_results_benchmark.csv available in artifacts

[MANUALLY ADDED]: CSV report in google sheets.

---------------------------------------------------

Summary:
  instructions:
    status:   No significant changes detected 👍
    counts:   [total 304 | new 285 | improved 0 | regressed 0 | unchanged 19]
    change:   [min 0 | med 0 | max 0]
    change %: [min 0.00% | med 0.00% | max 0.00%]

  heap_increase:
    status:   No significant changes detected 👍
    counts:   [total 304 | new 285 | improved 0 | regressed 0 | unchanged 19]
    change:   [min 0 | med 0 | max 0]
    change %: [min 0.00% | med 0.00% | max 0.00%]

  stable_memory_increase:
    status:   No significant changes detected 👍
    counts:   [total 304 | new 285 | improved 0 | regressed 0 | unchanged 19]
    change:   [min 0 | med 0 | max 0]
    change %: [min 0.00% | med 0.00% | max 0.00%]

---------------------------------------------------

Only significant changes:
| status | name                                               |     ins |  ins Δ% | HI |  HI Δ% | SMI |  SMI Δ% |
|--------|----------------------------------------------------|---------|---------|----|--------|-----|---------|
|  new   | btreemap_v2_contains_10mib_values                  | 159.10M |         |  0 |        |   0 |         |
|  new   | btreemap_v2_contains_10mib_values::node_load_v2    | 159.04M |         |  0 |        |   0 |         |
|  new   | btreemap_v2_contains_blob8_u64                     | 330.70M |         |  0 |        |   0 |         |
|  new   | btreemap_v2_contains_blob8_u64::node_load_v2       | 242.34M |         |  0 |        |   0 |         |
|  new   | btreemap_v2_contains_blob_1024_128                 |   4.95B |         |  0 |        |   0 |         |
|  new   | btreemap_v2_contains_blob_1024_128::node_load_v2   |   4.53B |         |  0 |        |   0 |         |
|  new   | btreemap_v2_contains_blob_128_128                  | 979.96M |         |  0 |        |   0 |         |
|  new   | btreemap_v2_contains_blob_128_128::node_load_v2    | 851.42M |         |  0 |        |   0 |         |
|  new   | btreemap_v2_contains_blob_16_128                   | 354.19M |         |  0 |        |   0 |         |
|  new   | btreemap_v2_contains_blob_16_128::node_load_v2     | 264.94M |         |  0 |        |   0 |         |
|  new   | btreemap_v2_contains_blob_256_128                  |   1.53B |         |  0 |        |   0 |         |
|  new   | btreemap_v2_contains_blob_256_128::node_load_v2    |   1.36B |         |  0 |        |   0 |         |
|  new   | btreemap_v2_contains_blob_32_1024                  | 393.23M |         |  0 |        |   0 |         |
|  new   | btreemap_v2_contains_blob_32_1024::node_load_v2    | 297.40M |         |  0 |        |   0 |         |
|  new   | btreemap_v2_contains_blob_32_128                   | 389.67M |         |  0 |        |   0 |         |
|  new   | btreemap_v2_contains_blob_32_128::node_load_v2     | 294.34M |         |  0 |        |   0 |         |
|  new   | btreemap_v2_contains_blob_32_16                    | 391.32M |         |  0 |        |   0 |         |
|  new   | btreemap_v2_contains_blob_32_16::node_load_v2      | 297.74M |         |  0 |        |   0 |         |
|  new   | btreemap_v2_contains_blob_32_256                   | 397.28M |         |  0 |        |   0 |         |
|  new   | btreemap_v2_contains_blob_32_256::node_load_v2     | 299.07M |         |  0 |        |   0 |         |
|  new   | btreemap_v2_contains_blob_32_32                    | 393.79M |         |  0 |        |   0 |         |
|  new   | btreemap_v2_contains_blob_32_32::node_load_v2      | 298.04M |         |  0 |        |   0 |         |
|  new   | btreemap_v2_contains_blob_32_4                     | 390.83M |         |  0 |        |   0 |         |
|  new   | btreemap_v2_contains_blob_32_4::node_load_v2       | 295.55M |         |  0 |        |   0 |         |
|  new   | btreemap_v2_contains_blob_32_512                   | 390.58M |         |  0 |        |   0 |         |
|  ...   | ... 688 rows omitted ...                           |         |         |    |        |     |         |
|  new   | btreemap_v2_scan_iter_rev_20_10mib::node_load_v2   |  18.46M |         |  0 |        |   0 |         |
|  new   | btreemap_v2_scan_keys_1k_0b                        |   1.17M |         |  0 |        |   0 |         |
|  new   | btreemap_v2_scan_keys_1k_0b::node_load_v2          | 583.75K |         |  0 |        |   0 |         |
|  new   | btreemap_v2_scan_keys_1k_10kib                     |   2.70M |         |  0 |        |   0 |         |
|  new   | btreemap_v2_scan_keys_1k_10kib::node_load_v2       |   2.07M |         |  0 |        |   0 |         |
|  new   | btreemap_v2_scan_keys_20_10mib                     |  18.47M |         |  0 |        |   0 |         |
|  new   | btreemap_v2_scan_keys_20_10mib::node_load_v2       |  18.46M |         |  0 |        |   0 |         |
|  new   | btreemap_v2_scan_keys_rev_1k_0b                    |   1.19M |         |  0 |        |   0 |         |
|  new   | btreemap_v2_scan_keys_rev_1k_0b::node_load_v2      | 582.80K |         |  0 |        |   0 |         |
|  new   | btreemap_v2_scan_keys_rev_1k_10kib                 |   2.57M |         |  0 |        |   0 |         |
|  new   | btreemap_v2_scan_keys_rev_1k_10kib::node_load_v2   |   1.93M |         |  0 |        |   0 |         |
|  new   | btreemap_v2_scan_keys_rev_20_10mib                 |  18.47M |         |  0 |        |   0 |         |
|  new   | btreemap_v2_scan_keys_rev_20_10mib::node_load_v2   |  18.46M |         |  0 |        |   0 |         |
|  new   | btreemap_v2_scan_values_1k_0b                      |   1.72M |         |  0 |        |   0 |         |
|  new   | btreemap_v2_scan_values_1k_0b::node_load_v2        | 583.75K |         |  0 |        |   0 |         |
|  new   | btreemap_v2_scan_values_1k_10kib                   |  57.32M |         |  0 |        |   0 |         |
|  new   | btreemap_v2_scan_values_1k_10kib::node_load_v2     |   1.93M |         |  0 |        |   0 |         |
|  new   | btreemap_v2_scan_values_20_10mib                   |   1.10B |         |  0 |        |   0 |         |
|  new   | btreemap_v2_scan_values_20_10mib::node_load_v2     |  18.46M |         |  0 |        |   0 |         |
|  new   | btreemap_v2_scan_values_rev_1k_0b                  |   1.72M |         |  0 |        |   0 |         |
|  new   | btreemap_v2_scan_values_rev_1k_0b::node_load_v2    | 582.80K |         |  0 |        |   0 |         |
|  new   | btreemap_v2_scan_values_rev_1k_10kib               |  57.28M |         |  0 |        |   0 |         |
|  new   | btreemap_v2_scan_values_rev_1k_10kib::node_load_v2 |   1.93M |         |  0 |        |   0 |         |
|  new   | btreemap_v2_scan_values_rev_20_10mib               |   1.10B |         |  0 |        |   0 |         |
|  new   | btreemap_v2_scan_values_rev_20_10mib::node_load_v2 |  18.46M |         |  0 |        |   0 |         |

---------------------------------------------------
CSV results saved to canbench_results.csv

@maksymar maksymar changed the title [DEBUG] testing base line test: refactor BTreeMap tests to improve coverage and readability Apr 22, 2025
@maksymar maksymar changed the title test: refactor BTreeMap tests to improve coverage and readability test: refactor BTreeMap benches to improve coverage and readability Apr 22, 2025
Copilot

This comment was marked as outdated.

@maksymar maksymar marked this pull request as draft May 12, 2025 11:33
@maksymar maksymar requested a review from Copilot May 19, 2025 09:50
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the BTreeMap benchmarks by introducing support for unbounded types via a new FixedVec, removing all legacy V1 benchmarks, and updating the main benchmark harness for coverage and readability improvements.

  • Add a FixedVec type with Storable implementation to cover unbounded-size tests.
  • Remove the generated canbench_results.csv file to avoid stale benchmark data.
  • Update benchmarks/src/main.rs to import FixedVec and provide a Random implementation for it.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

File Description
src/storable.rs Introduced FixedVec, implemented Storable
canbench_results.csv Deleted outdated benchmark results
benchmarks/src/main.rs Imported FixedVec and added Random impl
Comments suppressed due to low confidence (3)

src/storable.rs:201

  • [nitpick] The method name from may be confusing and doesn't implement the standard From trait. Rename it to new or implement From<&[u8]> for FixedVec<N> for consistency with Rust conventions.
    pub fn from(slice: &[u8]) -> Self {

src/storable.rs:192

  • [nitpick] Consider expanding the doc comment to explain that FixedVec is always padded to length N, and document the behavior of max_size and the constructor.
/// Byte-vector for testing size N; otherwise just a Vec<u8>.

src/storable.rs:210

  • There are no unit tests for FixedVec. Adding tests to verify padding, max_size, serialization, and deserialization behavior would improve confidence in its correctness.
impl<const N: usize> Storable for FixedVec<N> {

@maksymar maksymar marked this pull request as ready for review May 19, 2025 10:23
@maksymar
Copy link
Contributor Author

@dsarlis I am reviving this PR again, removed V1 benchmarks and synced to the new canbench reporting format. PTAL

@maksymar maksymar requested a review from dsarlis May 19, 2025 10:24
@maksymar maksymar changed the title test: refactor BTreeMap benches to improve coverage and readability test: improve BTreeMap bench coverage and readability May 19, 2025
Copy link
Member

@dsarlis dsarlis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still adding new benchmarks must be handled with care because pocket_ic has a limitation on the number of tests (10k) and the total length of test names (20k chars). This limit is going to be increased soon.

From the PR description, is this still true? I suppose not because the new version of canbench should have lifted this restriction.

@maksymar maksymar merged commit eb53ee8 into main May 19, 2025
13 checks passed
@maksymar maksymar deleted the maksym/base branch May 19, 2025 14: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.

2 participants