Skip to content
This repository has been archived by the owner on Aug 4, 2021. It is now read-only.

perf: cache file stats/reads #126

Merged
merged 1 commit into from
Mar 7, 2018
Merged

Conversation

keithamus
Copy link
Contributor

This is some work towards fixing (not entirely) #121. File reads and stat calls are cached for the lifetime of the code execution. This takes the number of times files are stated dramatically down (on our build, one file goes from 13,000 stat calls to 1,300), however browser-resolve still does many file reads/stats using its own mechanism - so further PRs will be arriving next week around this, as files are still read multiple times when they don't need to be.

It may be worth clearing the read file cache out on an ongenerate rollup call or something?

Thoughts/comments welcome.

/cc @mislav who worked on this with me

Copy link
Member

@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

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

Hi, sorry for not getting back to you earlier. I think this looks really nice. I've been checking for issues this might be causing and the only thing I could come up is if an npm install happens while in watch mode which changes the availability or position of files in node_modules. But I guess the prudent user will know to restart watch mode in such a situation anyway so I guess this could be ignored for now. Great work!

@lukastaegert lukastaegert added this to the 3.1.0 milestone Feb 20, 2018
@keithamus
Copy link
Contributor Author

Yes the other issue is if a file gets into an error state, then that error state is cached indefinitely. I think I'll address some of these concerns though as Im not entirely comfortable merging this PR in this state.

@keithamus keithamus force-pushed the cache-reads branch 2 times, most recently from 6ccdb4f to 0c3689c Compare February 20, 2018 10:50
@keithamus
Copy link
Contributor Author

@lukastaegert would be good to get your thoughts about this new change. I've changed two things since last review:

@lukastaegert
Copy link
Member

Thanks for your efforts here! Would be nice if you could rebase against current master as this will add a "prepare" script that should enable direct installation from Github. This should make it easier to test this PR in different scenarios.

@keithamus
Copy link
Contributor Author

Rebased 😸

Copy link
Member

@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

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

Very nice improvements (except for the probably wrong plugin hook). Will need to test this a little more, though. If there are any more concerns from your side with releasing this, please let me know!

src/index.js Outdated
err => {
if (err.code == 'ENOENT') return false;
throw err;
}
Copy link
Member

Choose a reason for hiding this comment

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

Why not just put this into the catch block below? Also, using both the second then argument and catch seems a little over the top to me... 😉

src/index.js Outdated
isFileCache = {};
readFileCache = {};
},

Copy link
Member

Choose a reason for hiding this comment

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

Very good idea but you probably mean onwrite

@keithamus
Copy link
Contributor Author

Fixed up those issues. I'm comfortable enough with this now. We've been testing this internally for a while now and it works well.

@lukastaegert
Copy link
Member

Hey @keithamus, sorry for not getting back to you. So it seems that while I do not have the npm publishing rights for this plugin, you do have them. So I was wondering if you would want to take it upon you to release the latest PRs for this plugin?
I'm also asking because @kellyselden was asking me about the state of #140 and #141.

@keithamus
Copy link
Contributor Author

For sure - are you happy with each of these PRs?

@keithamus keithamus merged commit f65152d into rollup:master Mar 7, 2018
@keithamus keithamus deleted the cache-reads branch March 7, 2018 10:28
@lukastaegert
Copy link
Member

Yup, thanks for taking care of this 👍! This really helps @guybedford and myself concentrate on maintaining rollup core. If you want a review from us for anything, don't hesitate to add us as reviewers.

@lukastaegert
Copy link
Member

By the way, at the moment I am fledging out a solution to get precise performance timings for rollup both for internal code as well as time spend in plugin hooks rollup/rollup#2045.

When bundling rollup with rollup-plugin-node-resolve@3.0.0, rollup spends about 180ms resolving ids on my machine. With rollup-plugin-node-resolve@3.2.0, this drops to 4ms! Amazing work indeed! 🎉

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

Successfully merging this pull request may close these issues.

2 participants