Skip to content

perf: optimize value swap in BTreeMap#333

Merged
maksymar merged 4 commits intomainfrom
maksym/swap_value
Jun 5, 2025
Merged

perf: optimize value swap in BTreeMap#333
maksymar merged 4 commits intomainfrom
maksym/swap_value

Conversation

@maksymar
Copy link
Copy Markdown
Contributor

@maksymar maksymar commented Jun 4, 2025

This PR optimizes the value update mechanism in BTreeMap by introducing a dedicated method for replacing values without touching the keys.

@maksymar maksymar changed the title perf: optimize updating value by the same key in BTreeMap perf: optimize value swap in BTreeMap Jun 4, 2025
@maksymar maksymar requested a review from Copilot June 4, 2025 12:44

This comment was marked as outdated.

@maksymar maksymar requested a review from Copilot June 4, 2025 12:53

This comment was marked as outdated.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 4, 2025

canbench 🏋 (dir: ./benchmarks/compare) e26098d 2025-06-04 15:08:33 UTC

./benchmarks/compare/canbench_results.yml is up to date
📦 canbench_results_compare.csv available in artifacts

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

Summary:
  instructions:
    status:   No significant changes detected 👍
    counts:   [total 18 | new 0 | improved 0 | regressed 0 | unchanged 18]
    change:   [max +53.05M | p75 0 | median 0 | p25 0 | min -8.77K]
    change %: [max +0.06% | p75 0.00% | median 0.00% | p25 0.00% | min -0.00%]

  heap_increase:
    status:   No significant changes detected 👍
    counts:   [total 18 | new 0 | improved 0 | regressed 0 | unchanged 18]
    change:   [max 0 | p75 0 | median 0 | p25 0 | min 0]
    change %: [max 0.00% | p75 0.00% | median 0.00% | p25 0.00% | min 0.00%]

  stable_memory_increase:
    status:   No significant changes detected 👍
    counts:   [total 18 | new 0 | improved 0 | regressed 0 | unchanged 18]
    change:   [max 0 | p75 0 | median 0 | p25 0 | min 0]
    change %: [max 0.00% | p75 0.00% | median 0.00% | p25 0.00% | min 0.00%]

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

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 4, 2025

canbench 🏋 (dir: ./benchmarks/vec) e26098d 2025-06-04 15:07:45 UTC

./benchmarks/vec/canbench_results.yml is up to date
📦 canbench_results_vec.csv available in artifacts

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

Summary:
  instructions:
    status:   No significant changes detected 👍
    counts:   [total 16 | new 0 | improved 0 | regressed 0 | unchanged 16]
    change:   [max 0 | p75 0 | median 0 | p25 0 | min 0]
    change %: [max 0.00% | p75 0.00% | median 0.00% | p25 0.00% | min 0.00%]

  heap_increase:
    status:   No significant changes detected 👍
    counts:   [total 16 | new 0 | improved 0 | regressed 0 | unchanged 16]
    change:   [max 0 | p75 0 | median 0 | p25 0 | min 0]
    change %: [max 0.00% | p75 0.00% | median 0.00% | p25 0.00% | min 0.00%]

  stable_memory_increase:
    status:   No significant changes detected 👍
    counts:   [total 16 | new 0 | improved 0 | regressed 0 | unchanged 16]
    change:   [max 0 | p75 0 | median 0 | p25 0 | min 0]
    change %: [max 0.00% | p75 0.00% | median 0.00% | p25 0.00% | min 0.00%]

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

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 4, 2025

canbench 🏋 (dir: ./benchmarks/btreemap) e26098d 2025-06-04 15:09:26 UTC

./benchmarks/btreemap/canbench_results.yml is up to date
📦 canbench_results_btreemap.csv available in artifacts

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

Summary:
  instructions:
    status:   No significant changes detected 👍
    counts:   [total 285 | new 0 | improved 0 | regressed 0 | unchanged 285]
    change:   [max +269.56K | p75 0 | median 0 | p25 0 | min -1.03M]
    change %: [max +0.06% | p75 0.00% | median 0.00% | p25 0.00% | min -0.17%]

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

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

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

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 4, 2025

canbench 🏋 (dir: ./benchmarks/memory_manager) e26098d 2025-06-04 15:07:37 UTC

./benchmarks/memory_manager/canbench_results.yml is up to date
📦 canbench_results_memory-manager.csv available in artifacts

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

Summary:
  instructions:
    status:   No significant changes detected 👍
    counts:   [total 3 | new 0 | improved 0 | regressed 0 | unchanged 3]
    change:   [max 0 | p75 0 | median 0 | p25 0 | min 0]
    change %: [max 0.00% | p75 0.00% | median 0.00% | p25 0.00% | min 0.00%]

  heap_increase:
    status:   No significant changes detected 👍
    counts:   [total 3 | new 0 | improved 0 | regressed 0 | unchanged 3]
    change:   [max 0 | p75 0 | median 0 | p25 0 | min 0]
    change %: [max 0.00% | p75 0.00% | median 0.00% | p25 0.00% | min 0.00%]

  stable_memory_increase:
    status:   No significant changes detected 👍
    counts:   [total 3 | new 0 | improved 0 | regressed 0 | unchanged 3]
    change:   [max 0 | p75 0 | median 0 | p25 0 | min 0]
    change %: [max 0.00% | p75 0.00% | median 0.00% | p25 0.00% | min 0.00%]

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

@maksymar maksymar requested a review from Copilot June 4, 2025 13:02
Copy link
Copy Markdown
Contributor

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 optimizes the value update mechanism in BTreeMap by introducing a dedicated method for replacing values. It refactors the code to use a new swap_value function in node.rs and an update_value helper in btreemap.rs, streamlining and unifying the update process.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/btreemap/node.rs Added swap_value to replace a node’s value and extract the old value efficiently.
src/btreemap.rs Replaced direct swap_entry calls with update_value to standardize value updates and persist node changes.
Comments suppressed due to low confidence (1)

src/btreemap/node.rs:159

  • [nitpick] The name 'swap_value' may be misleading as it implies a bilateral swap, but it only replaces the value; consider renaming it to 'replace_value' for improved clarity.
/// Replaces the value at `idx` and returns the old one.

@maksymar maksymar marked this pull request as ready for review June 4, 2025 14:56
@maksymar maksymar requested a review from a team as a code owner June 4, 2025 14:56
@maksymar maksymar merged commit 087bbf4 into main Jun 5, 2025
14 checks passed
@maksymar maksymar deleted the maksym/swap_value branch June 5, 2025 07:33
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