Repository navigation
[PM-45308] perf(cli): Re-read storage only when data.json changed - #23955
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## cli-perf/02-sync-storage-lock #23955 +/- ##
================================================================
Coverage ? 59.31%
================================================================
Files ? 4699
Lines ? 148727
Branches ? 23719
================================================================
Hits ? 88220
Misses ? 54344
Partials ? 6163 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
🤖 Bitwarden Claude Code ReviewOverall Assessment: APPROVE Reviewed the read cache added to the CLI |
9c3e002 to
e7947df
Compare
e7947df to
1039f6f
Compare
Every storage read parsed the whole data.json. A single `bw get item` reads storage 57 times, and with a large vault the file is ~19 MB, so parsing it again dominated the command. Keep the parsed contents and re-read only when the file's inode, size, mtime or ctime show another process changed it. Values are copied on get and stored as their JSON round-trip on save, so callers see exactly what a re-read from disk used to return.
1039f6f to
6187078
Compare
dani-garcia
left a comment
There was a problem hiding this comment.
Looks fairly reasonable to me.
For most commands except serve, we could also skip the stat call entirely, and just assume the cache hasn't changed mid command run, but not sure if that would be much faster.
| private readForNoCache() { | ||
| if (!this.allowCache) { | ||
| this.db.read(); | ||
| if (this.allowCache) { |
There was a problem hiding this comment.
I wonder why we even have this parameter, it seems like we always pass false on the constructor 🤷
There was a problem hiding this comment.
Yeah... I have not dug.... :(
🎟️ Tracking
https://bitwarden.atlassian.net/browse/PM-45308
📔 Objective
Every storage read parsed the whole data.json; one
bw get itemread storage 57 times, and with a large vault the file is ~19 MB. The parsed contents are now kept and re-read only when the file's inode, size, mtime or ctime show another process changed it. Values are copied on get and stored as their JSON round-trip on save, so callers see exactly what a re-read from disk used to return.⏱️ Benchmark
Before = the previous PR in this stack, after = this PR.
bw get item <id>bw get password <id>bw list itemsbw statusProd build (
npm run build:oss:prod) run asnode build/bw.js, Node 25.9.0, Apple M5 Pro. Account with 11,996 items on vault.usdev.bitwarden.pw (data.json ~19 MB).