Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

cache-require-paths #11962

Closed
wants to merge 1 commit into from
Closed

cache-require-paths #11962

wants to merge 1 commit into from

Conversation

ayumi
Copy link
Contributor

@ayumi ayumi commented Nov 15, 2017

Add cache-require-paths.

BL version 1st start Subsequent starts
master 0147755 770 ms 770 ms
feature/require-faster 9ffc7ee 790 ms 700 ms

The first start is slightly slower (maybe due to writing the cache) but subsequent starts are faster.

Test plan:

  1. Try packaged build on MacOS, Linux and Windows.
  2. Try dev on MacOS, Linux and Windows.

Measuring perf

  1. Log run time of app/index.js from 0 to perWindowStateLoaded ready = true
    a. To L10 add:
const tStart = process.hrtime()

b. To L361 after ready = true add:

const tTime = process.hrtime(tStart)
console.log(`index.js window ready: ${tTime[0] * 1e3 + tTime[1] * 1e-6} ms`)
  1. Start brave and record the run time.
  2. Repeat

Note: when switching branches delete node_modules and reinstall to be sure the npm dedupe changes got applied

Submitter Checklist:

  • Submitted a ticket for my issue if one did not already exist.
  • Used Github auto-closing keywords in the commit message.
  • Added/updated tests for this change (for new code or code which already has tests).
  • Ran git rebase -i to squash commits (if needed).
  • Tagged reviewers and labelled the pull request as needed.

Test Plan:

Reviewer Checklist:

Tests

  • Adequate test coverage exists to prevent regressions
  • Tests should be independent and work correctly when run individually or as a suite ref
  • New files have MPL2 license header

@ayumi ayumi self-assigned this Nov 15, 2017
@ayumi ayumi added the perf label Nov 15, 2017
@ayumi ayumi changed the title [WIP] speed up require with cache and npm dedupe speed up require with cache and npm dedupe Nov 15, 2017
@ayumi ayumi changed the title speed up require with cache and npm dedupe cache-require-paths Nov 29, 2017
@bsclifton bsclifton added this to the 0.19.x Hotfix 9 milestone Dec 19, 2017
Copy link
Member

@bsclifton bsclifton left a comment

Choose a reason for hiding this comment

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

@ayumi can you please rebase this? I promise to review after that 😄

@bsclifton bsclifton modified the milestones: 0.19.x Hotfix 9, 0.21.x (Developer Channel) Dec 20, 2017
@ayumi
Copy link
Contributor Author

ayumi commented Dec 21, 2017

@bsclifton thanks for the reminder! I rebased and tried it out again on Linux (dev and built package)

Copy link
Contributor

@cezaraugusto cezaraugusto left a comment

Choose a reason for hiding this comment

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

++ confirmed the perf gains

has this dep passed through sec audit? if so lgtm

Copy link
Member

@bsclifton bsclifton left a comment

Choose a reason for hiding this comment

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

++

@bsclifton
Copy link
Member

Security review created https://github.com/brave/internal/issues/161

Will wait for results before merging

@diracdeltas
Copy link
Member

i wonder if we will run into cache invalidation issues? bahmutov/cache-require-paths#6

@diracdeltas
Copy link
Member

sorry, accidental close

@diracdeltas diracdeltas reopened this Dec 21, 2017
@bsclifton
Copy link
Member

bsclifton commented Dec 21, 2017

@ayumi do you know if the cache is invalidated at any point during each run? If not, we could encounter the problem @diracdeltas linked to when running from source (we wouldn't run into it for packaged builds though)

The issue linked does (for that use-case) propose a work-around using an npm hook

@ayumi
Copy link
Contributor Author

ayumi commented Dec 21, 2017

@diracdeltas @bsclifton That's a good catch. The only cache invalidation happens when the requiring a cached path fails, in that case it resolves from scratch: https://github.com/bahmutov/cache-require-paths/blob/master/index.js#L40

So it sounds like this may affect dev builds, however wouldn't affect packaged builds.
Would it be sufficient to add a post npm install hook to delete the cache file?

@bsclifton
Copy link
Member

@ayumi I think that would be perfect actually 😄 👍

Copy link
Member

@bsclifton bsclifton left a comment

Choose a reason for hiding this comment

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

Let's go with the invalidating using the install npm hook 😄

@bsclifton
Copy link
Member

pushing back a few releases - @ayumi we can re-review once the hook is done (per notes above) 😄

@bsclifton bsclifton modified the milestones: 0.21.x (Beta Channel), 0.23.x (Nightly Channel) Feb 8, 2018
@bsclifton
Copy link
Member

Closing PR for now- let's reopen if we have the time to revisit 😄

@bsclifton bsclifton closed this Feb 14, 2018
@bsclifton bsclifton removed this from the 0.23.x (Nightly Channel) milestone Feb 14, 2018
@bsclifton bsclifton mentioned this pull request Feb 14, 2018
@bsclifton bsclifton deleted the feature/require-faster branch July 27, 2018 17:31
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants