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

[PM-6163] Speed up list items command - Only call GetGlobals() when we actually need them #7855

Merged
merged 1 commit into from
Feb 20, 2024

Conversation

watzkuh
Copy link
Contributor

@watzkuh watzkuh commented Feb 8, 2024

Type of change

- [ ] Bug fix
- [ ] New feature development
- [ ] Tech debt (refactoring, code cleanup, dependency upgrades, etc)
- [ ] Build/deploy pipeline (DevOps)
- [X] Other

Objective

Speed up the CLI list items command (see issue #7742)

Code changes

  • state.service.ts : Only call GetGlobals() when we actually need them

Since we only need it as a backup if accountVaultTimeoutAction is null/undefined, there should be no need to call this function every time.

While the overhead may seem trivial at first glance, it can add up to a massive increase in runtime when the function is called repeatedly in quick succession (e.g. when running bw list items where it is executed once for every item).

In my concrete case this change leads to a 25x speedup.

Before:

❯ time node build/bw.js list items > /dev/null
node build/bw.js list items > /dev/null  14.33s user 4.59s system 23% cpu 1:21.04 total

After:

❯ time node build/bw.js list items > /dev/null
node build/bw.js list items > /dev/null  1.42s user 0.25s system 50% cpu 3.294 total

@bitwarden-bot
Copy link

Thank you for your contribution! We've added this to our internal Community PR board for review.
ID: PM-6163

@bitwarden-bot bitwarden-bot changed the title Speed up list items command - Only call GetGlobals() when we actually need them [PM-6163] Speed up list items command - Only call GetGlobals() when we actually need them Feb 8, 2024
@bitwarden-bot
Copy link

bitwarden-bot commented Feb 8, 2024

Logo
Checkmarx One – Scan Summary & Details1c1302e2-419e-4b8f-8638-dbfe670c06be

Fixed Issues

Severity Issue Source File / Package
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/services/autofill.service.spec.ts: 3699
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/services/autofill.service.spec.ts: 3672
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/services/autofill.service.spec.ts: 3654
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/services/autofill.service.spec.ts: 3690
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/services/autofill.service.spec.ts: 3701
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/services/autofill.service.spec.ts: 3700
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/services/autofill.service.spec.ts: 1316
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 51
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 39
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 34
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 45
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 46
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 37
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 45
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 42
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 51
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 39
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 46
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 34
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 41
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 35
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 43
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 37
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 36
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 46
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 50
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 37
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 40
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 50
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 39
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 38
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 46
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 50
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 41
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 43
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 50
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 31
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 54
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 36
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 31
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 45
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 40
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 35
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 54
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 51
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 45
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 44
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 42
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 31
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 43
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 34
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 35
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 38
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 42
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 51
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 41
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 54
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 40
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 44
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 36
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 44
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 54
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 38
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 39
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 40
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 54
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 31
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 41
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 54
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 37
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 43
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 50
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 38
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 51
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 34
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 50
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 41
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 42
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 40
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 40
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 43
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 45
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 36
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 43
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 51
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 42
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 54
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 39
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 45
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 34
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 50
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 42
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/services/autofill.service.spec.ts: 3610
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 45
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 36
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 44
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 44
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 39
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 34
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 37
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 50
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 45
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 34
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/services/autofill.service.spec.ts: 3663
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 40
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 51
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 35
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 43
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 46
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 41
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 38
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 50
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 51
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 35
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 35
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 39
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 31
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 31
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 31
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 46
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 37
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 50
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 35
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 31
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 37
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 45
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 38
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 51
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 44
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 45
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 44
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 38
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 34
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/services/autofill.service.spec.ts: 3645
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 37
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 54
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 46
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 36
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 43
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 46
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 39
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 46
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 37
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 40
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 41
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 36
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 43
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 37
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 43
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/services/autofill.service.spec.ts: 1588
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 46
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 31
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 41
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 50
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 51
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 36
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 42
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 36
LOW Use_Of_Hardcoded_Password /apps/browser/src/autofill/jest/autofill-mocks.ts: 34
LOW Use_Of_Hardcoded_Password

More results are available on AST platform

Since we only need it as a backup if accountVaultTimeoutAction is
null/undefined, there should be no need to call this function every time.

While the overhead may seem trivial at first glance, it can add up to a
massive increase in runtime when the function is called repeatedly in
quick succession (e.g. when running `bw list items` where it is executed
once for every item).

In my concrete case this change leads to a 20x speedup.
Copy link
Member

@dani-garcia dani-garcia left a comment

Choose a reason for hiding this comment

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

Hey @watzkuh, thanks for your PR! The change looks good, and I've tested and experienced the bw list items time go from 190 seconds to 4 seconds, I'm going to send this PR to QA for some final testing, as soon as it's done I'll merge this.

@dani-garcia dani-garcia removed the needs-qa Marks a PR as requiring QA approval label Feb 20, 2024
@dani-garcia
Copy link
Member

This has gone through QA and is ready to merge, thanks for your contribution!

@dani-garcia dani-garcia merged commit e823c27 into bitwarden:main Feb 20, 2024
113 of 125 checks passed
@luckman212
Copy link

Is this landed yet? I tested it with a prerelease artifact from 2024.5.0 and am still seeing extremely long list items runtimes, see #9142 (comment)

@oysandvik94
Copy link

Pretty slow for me too. I notice that i hangs a little bit after it prints out the results, so it's not getting the actual items that are slow. I feel like this is slow as well: bw unlock --session $BW_SESSION --check, around 800 ms. I run this in a script to check that my BW_SESSION is valid before I call list items, so together it's pretty slow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants