Skip to content

[PM-46036] perf(vault): Decrypt the whole vault in batches, not get_all() - #24241

Merged
quexten merged 3 commits into
mainfrom
km/ext-memory-batch-decrypt-all
Nov 6, 2026
Merged

quexten merged 3 commits into
mainfrom
km/ext-memory-batch-decrypt-all

Conversation

@quexten

@quexten quexten commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

🎟️ Tracking

PM-46036

📔 Objective

ciphers().get_all() has the SDK read every cipher from its state repository and return every full cipher view in one call: all encrypted inputs and decrypted outputs in SDK (WebAssembly) memory at once, which is never given back. The extension's service worker went from 3 MB to 130 MB of SDK memory after login on a 12k item vault.

We are introducing a temporary work around until platform's other improvements merge.

Measurements (old)

Measured on main (e44dc1f) with the e2e harness (#24239), 12k item vault, prod Chrome build. Memory from one run; footprint varies ±5% run to run. Unlock times are medians of 10, timed from the lock screen's form submit.

Phase Metric #24305 This PR Change
popup on vault extension process footprint (MB) 511.5 435.0 -15%
popup on vault popup JS heap (MB) 61.9 61.9 +0%
popup on vault popup SDK (WASM) memory (MB) 4.5 4.5 =
popup on vault service worker SDK (WASM) memory (MB) 130.3 64.7 -50%
unlocked, popup closed extension process footprint (MB) 384.3 308.5 -20%
unlocked, popup closed service worker JS heap (MB) 41.5 41.5 +0%
unlocked, popup closed decrypted cache in session storage (MB) 12.5 12.5 =
unlocked, popup closed plaintext passwords in service worker heap 12000 12000 =
5 autofills extension process footprint (MB) 403.9 325.8 -19%
service worker restarted extension process footprint (MB) 206.3 206.7 +0%
service worker restarted plaintext passwords in service worker heap 23997 23997 =
popup reopened 3× extension process footprint (MB) 251.8 251.0 -0%
Time to vault rendered (median of 10) #24305 This PR Change
master password unlock 1261.6 ms 1254.3 ms -1%
PIN unlock 1327 ms 1322.1 ms -0%
popup open while unlocked 644.5 ms 641.8 ms -0%

📸 Screenshots

N/A

@quexten
quexten added this pull request to stack #24243 October 29, 2026 04:20
@quexten quexten changed the title Decrypt the whole vault in batches, not get_all() perf(vault): Decrypt the whole vault in batches, not get_all() Oct 29, 2026
@codecov

codecov Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.66667% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 61.95%. Comparing base (4c8d0b3) to head (48e3633).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
libs/common/src/vault/services/cipher.service.ts 66.66% 4 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #24241   +/-   ##
=======================================
  Coverage   61.95%   61.95%           
=======================================
  Files        4928     4928           
  Lines      158958   158974   +16     
  Branches    25504    25504           
=======================================
+ Hits        98483    98495   +12     
- Misses      53711    53715    +4     
  Partials     6764     6764           

☔ 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 force-pushed the km/ext-memory-batch-decrypt-all branch 2 times, most recently from 43d61cf to a6ed509 Compare October 29, 2026 18:48
@quexten
quexten removed this pull request from stack #24243 October 29, 2026 18:49
@quexten
quexten added this pull request to stack #24279 October 29, 2026 19:24
@quexten
quexten force-pushed the km/ext-memory-batch-decrypt-all branch from a6ed509 to 110455e Compare October 30, 2026 04:59
@quexten
quexten force-pushed the km/ext-memory-batch-decrypt-all branch from 110455e to 5fce199 Compare October 30, 2026 05:30
@quexten quexten added the BEEEP BEEEEP Projects label Oct 30, 2026
@quexten quexten changed the title perf(vault): Decrypt the whole vault in batches, not get_all() [PM-46036] perf(vault): Decrypt the whole vault in batches, not get_all() Oct 30, 2026
@quexten
quexten force-pushed the km/ext-memory-batch-decrypt-all branch 2 times, most recently from d492898 to 6a9f9d5 Compare October 30, 2026 06:37
@quexten
quexten force-pushed the km/ext-memory-batch-decrypt-all branch from 6a9f9d5 to ed5a76c Compare October 30, 2026 06:38
@quexten
quexten removed this pull request from stack #24279 October 30, 2026 06:42
@quexten
quexten added this pull request to stack #24303 October 30, 2026 06:42
@quexten quexten added the ai-review Request a Claude code review label Oct 30, 2026
@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

🤖 Bitwarden Claude Code Review

Overall Assessment: APPROVE

This PR replaces the SDK's getAllDecrypted call in CipherService.getAllDecryptedIncludingRestricted with a temporary helper. The helper reads ciphers$ and decrypts one cipher at a time through cipherEncryptionService.decrypt, which keeps SDK memory from growing to the size of the vault. A failed decrypt is still caught and recorded the same way: CipherEncryptionService.decrypt maps SDK errors to EMPTY, so firstValueFrom rejects, and the failure placeholder ([error: cannot decrypt], decryptionFailure = true) matches the existing decryptCiphersWithSdk pattern. The spec updates mock the new path for success, localData hydration and the restricted-filter cases, and I found no issues that need changes.

@quexten
quexten force-pushed the km/ext-memory-batch-decrypt-all branch from ed5a76c to 4fc0b54 Compare October 30, 2026 07:58
@quexten
quexten requested a review from a team as a code owner November 2, 2026 06:03
@quexten
quexten force-pushed the km/ext-memory-batch-decrypt-all branch from 5538cb5 to 470ab35 Compare November 2, 2026 06:09
@quexten quexten linked an issue Nov 3, 2026 that may be closed by this pull request
1 task done
Base automatically changed from km/ext-memory-batch-list-decrypt to main November 5, 2026 04:45
@quexten
quexten requested review from a team as code owners November 5, 2026 04:45
get_all() has the SDK read every cipher from its state repository and
return every full cipher view in one call, so all encrypted inputs and
decrypted outputs sit in WebAssembly memory at once. That memory is
never given back: the extension's service worker grew from 3 MB to
130 MB on a 12k item vault after login.

CipherSdkService.getAllDecrypted becomes legacyDecryptFullViewList,
which takes the encrypted ciphers from state and decrypts them 250 at
a time with decrypt_list_full_with_failures, bounding the peak to one
batch. It is named legacy because it still holds every full view at
once; going over the whole vault belongs in an iterator in the SDK.

The ciphers are read without localData, which is attached to the views
afterwards, so a failure to read it no longer fails the decrypt.
@quexten
quexten force-pushed the km/ext-memory-batch-decrypt-all branch from 470ab35 to e228ce2 Compare November 5, 2026 04:46
@quexten
quexten removed request for a team, mzieniukbw and vleague2 November 5, 2026 07:54
@quexten
quexten marked this pull request as draft November 5, 2026 07:55
Replace the batching switch with a temporary serial decrypt. The
getAllDecrypted call stays commented out so the switch back is trivial.
One cipher per SDK call keeps WebAssembly memory from growing to the
size of the vault.
Keep the temporary fix local to CipherService: decrypt each cipher
with the existing single-cipher decrypt and leave CipherSdkService
untouched. Stays until PM-46138 merges.
@quexten quexten added the t:bugfix Change Type - Bugfix label Nov 5, 2026
@quexten
quexten marked this pull request as ready for review November 5, 2026 08:12
@gbubemismith

Copy link
Copy Markdown
Contributor

@quexten should the description be updated since we now handle the decryption serially? and did you re-do the benchmarks?

@quexten

quexten commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

Re-measured against main (harness #24239 head), 12k item vault on usdev, prod Chrome build. Two memory runs per side; unlock is the median of 10 per run.

Phase Metric main PR Change
popup on vault footprint (MB) 582.8 509.2 -13%
popup on vault service worker WASM (MB) 130.3 63.8 -51%
unlocked, popup closed footprint (MB) 381.3 312.2 -18%
5 autofills footprint (MB) 401.0 333.6 -17%
service worker restarted footprint (MB) 206.2 208.1 +1%
popup reopened 3× footprint (MB) 247.7 250.9 +1%

Popup WASM, service worker JS heap, decrypted cache and plaintext password count are unchanged.

Time to vault rendered main PR Change
master password 1369 ms 1464 ms +7%
PIN 1351 ms 1433 ms +6%
popup open while unlocked 667 ms 655 ms -2%

Unlock is about 100 ms slower than main, consistently across runs (master password: 1371 / 1367 ms on main, 1470 / 1459 ms on the PR). The PIN figure has one PR run; the second failed on a harness flake. Not profiled; likely the serial decrypt.

@quexten

quexten commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor Author

@gbubemismith I've added the re-measured bench numbers above. The unlock time is slightly larger for large vaults, but the follow-up PR's will reduce it again. The memory usage is still vastly decreased.

@quexten
quexten merged commit f97d7a3 into main Nov 6, 2026
192 of 198 checks passed
@quexten
quexten deleted the km/ext-memory-batch-decrypt-all branch November 6, 2026 00:50
@djsmith85 djsmith85 added browser Browser Extension desktop Desktop Application cli CLI Application web labels Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-review Request a Claude code review BEEEP BEEEEP Projects browser Browser Extension cli CLI Application desktop Desktop Application t:bugfix Change Type - Bugfix web

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optimize memory footprint throughout the extension

3 participants