Skip to content

[PM-45308] perf(cli): Copy cached storage values without structuredClone - #23956

Merged
quexten merged 1 commit into
cli-perf/03-storage-read-cachefrom
cli-perf/04-copy-json
Oct 21, 2026
Merged

quexten merged 1 commit into
cli-perf/03-storage-read-cachefrom
cli-perf/04-copy-json

Conversation

@quexten

@quexten quexten commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

🎟️ Tracking

https://bitwarden.atlassian.net/browse/PM-45308

📔 Objective

The storage cache returns a copy on every get, and a command reads the whole ciphers value (~16 MB for a large vault) at least once. structuredClone took ~22 ms for it. The cache only ever holds plain JSON, so a direct recursive copy gives the same result in ~6 ms. End to end the gain is small: the medians below improve, but the rounds overlap, so it is within run-to-run noise.

⏱️ Benchmark

Before = the previous PR in this stack, after = this PR.

Command Output before Output after Change Exit before Exit after Change
bw get item <id> 452 ms 428 ms −5% 458 ms 434 ms −5%
bw get password <id> 459 ms 436 ms −5% 466 ms 442 ms −5%
bw list items 939 ms 925 ms −2% 951 ms 937 ms −1%
bw status 399 ms 399 ms +0% 405 ms 405 ms −0%

Prod build (npm run build:oss:prod) run as node build/bw.js, Node 25.9.0, Apple M5 Pro. Account with 11,996 items on vault.usdev.bitwarden.pw (data.json ~19 MB), Bitwarden Desktop running. Harness apps/cli/perf/bench.mjs.

@codecov

codecov Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 59.32%. Comparing base (6187078) to head (d07650a).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@                       Coverage Diff                       @@
##           cli-perf/03-storage-read-cache   #23956   +/-   ##
===============================================================
  Coverage                           59.31%   59.32%           
===============================================================
  Files                                4699     4699           
  Lines                              148727   148735    +8     
  Branches                            23719    23721    +2     
===============================================================
+ Hits                                88220    88232   +12     
+ Misses                              54344    54340    -4     
  Partials                             6163     6163           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@quexten quexten added the t:bugfix Change Type - Bugfix label Oct 19, 2026
@quexten
quexten marked this pull request as ready for review October 19, 2026 12:08
@quexten
quexten requested a review from a team as a code owner October 19, 2026 12:08
@quexten
quexten requested a review from dani-garcia October 19, 2026 12:08
@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

🤖 Bitwarden Claude Code Review

Overall Assessment: APPROVE

This PR replaces structuredClone with a recursive copyJson helper in LowdbStorageService.get, and adds a test showing that a caller who mutates nested values from a get does not change what the store holds. The helper assumes the store only holds plain JSON. That assumption holds: save stores the JSON round-trip of its input, init parses data.json, and every constructor call passes null defaults, so no values get in that skip serialization. Null handling, primitives, arrays, and the val == null early return behave the same as before.

dani-garcia
dani-garcia previously approved these changes Oct 19, 2026

@dani-garcia dani-garcia left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sounds reasonable, I'm surprised structuredClone is that slow

The storage cache returns a copy on every get, and a command reads the
whole ciphers value (~16 MB for a large vault) at least once.
structuredClone took ~22 ms for it. The cache only ever holds plain JSON,
so a direct recursive copy gives the same result in ~6 ms.
@quexten
quexten force-pushed the cli-perf/04-copy-json branch from 2b39f26 to d07650a Compare October 21, 2026 10:42
@quexten
quexten merged commit 0a9757c into main Oct 21, 2026
76 of 77 checks passed
@quexten
quexten deleted the cli-perf/04-copy-json branch October 21, 2026 11:50
@djsmith85 djsmith85 added the cli CLI Application label Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI Application t:bugfix Change Type - Bugfix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants