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(sidecar): ScoreCache for account_states #399

Merged
merged 18 commits into from
Nov 27, 2024
Merged

Conversation

thedevbirb
Copy link
Contributor

@thedevbirb thedevbirb commented Nov 19, 2024

Related to #393, this PR introduces a wrapper over HashMap called ScoreCache that implements a scoring system on get, insert and update operations.

The map size can be configured, with a default of 1 MiB that should hold around 15k account state entries considering also its key. For account states in particular a metrics bolt_sidecar_account_states has been added to track its usage.

ScoreCache vs HashMap/ScoreCache Insert -- size: 1000
                        time:   [16.345 µs 16.745 µs 17.213 µs]
                        change: [-4.8838% -1.1181% +2.2086%] (p = 0.54 > 0.05)
                        No change in performance detected.
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high mild
ScoreCache vs HashMap/HashMap Insert -- size: 1000
                        time:   [14.296 µs 14.488 µs 14.660 µs]
                        change: [-2.9083% +0.4949% +3.8702%] (p = 0.77 > 0.05)
                        No change in performance detected.
ScoreCache vs HashMap/ScoreCache Get -- size: 1000
                        time:   [15.983 µs 16.516 µs 17.003 µs]
                        change: [-3.5447% +5.5430% +15.125%] (p = 0.22 > 0.05)
                        No change in performance detected.
ScoreCache vs HashMap/HashMap Get -- size: 1000
                        time:   [13.273 µs 13.756 µs 14.232 µs]
                        change: [-5.4725% +1.4866% +8.8014%] (p = 0.69 > 0.05)
                        No change in performance detected.
ScoreCache vs HashMap/ScoreCache Update -- size: 1000
                        time:   [16.918 µs 17.405 µs 17.815 µs]
                        change: [-9.9428% -2.4709% +5.4745%] (p = 0.54 > 0.05)
                        No change in performance detected.
ScoreCache vs HashMap/HashMap Update -- size: 1000
                        time:   [13.179 µs 13.487 µs 13.747 µs]
                        change: [-2.3176% +4.8491% +12.955%] (p = 0.22 > 0.05)
                        No change in performance detected.
Found 2 outliers among 100 measurements (2.00%)
  1 (1.00%) high mild
  1 (1.00%) high severe

@thedevbirb thedevbirb added the C: bolt-sidecar Component: bolt-sidecar label Nov 19, 2024
@thedevbirb thedevbirb changed the title feat(sidecar): LowestScoreMap for account_states feat(sidecar): ScoreCache for account_states Nov 25, 2024
@thedevbirb thedevbirb marked this pull request as ready for review November 25, 2024 16:36
@thedevbirb
Copy link
Contributor Author

Open for a first review!

Copy link
Collaborator

@merklefruit merklefruit left a comment

Choose a reason for hiding this comment

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

Love it! Great work

bolt-sidecar/src/common/mod.rs Outdated Show resolved Hide resolved
bolt-sidecar/src/common/score_cache.rs Show resolved Hide resolved
bolt-sidecar/src/common/score_cache.rs Show resolved Hide resolved
bolt-sidecar/src/common/score_cache.rs Show resolved Hide resolved
bolt-sidecar/src/state/execution.rs Outdated Show resolved Hide resolved
@thedevbirb thedevbirb force-pushed the lore/feat/score-map branch 2 times, most recently from 4d6e866 to dd91eae Compare November 27, 2024 09:43
Copy link
Collaborator

@merklefruit merklefruit left a comment

Choose a reason for hiding this comment

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

Great!

bolt-sidecar/src/common/mod.rs Outdated Show resolved Hide resolved
bolt-sidecar/src/config/limits.rs Outdated Show resolved Hide resolved
bolt-sidecar/src/state/account_state.rs Show resolved Hide resolved
bolt-sidecar/src/state/execution.rs Outdated Show resolved Hide resolved
bolt-sidecar/benches/score_cache.rs Outdated Show resolved Hide resolved
bolt-sidecar/benches/score_cache.rs Outdated Show resolved Hide resolved
bolt-sidecar/benches/score_cache.rs Outdated Show resolved Hide resolved
// Insert benchmark
group.bench_function("ScoreCache Insert", |b| {
b.iter(|| {
for i in 0..1000 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider varying sizes of operations (1000, 10k, 100k) to understand how perf varies

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since I want to measure the raw overhead of modifying the score when doing get, insert, update operations I don't think there is a big advantage in testing different sizes. Also it slows down the benchmarking by really a lot. Just 1000 iterations takes a couple of mins on a M3 pro cpu

Copy link
Contributor

@estensen estensen left a comment

Choose a reason for hiding this comment

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

But don't wanna block this from merging

@thedevbirb
Copy link
Contributor Author

But don't wanna block this from merging

No worries! It was indeed great feedback. Pushing a commit soon to address it

Copy link
Contributor

@mempirate mempirate left a comment

Choose a reason for hiding this comment

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

Nice job, LGTM

@thedevbirb thedevbirb merged commit bd9d4bf into unstable Nov 27, 2024
3 checks passed
@thedevbirb thedevbirb deleted the lore/feat/score-map branch November 27, 2024 13:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: bolt-sidecar Component: bolt-sidecar
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants