-
Notifications
You must be signed in to change notification settings - Fork 153
lazy config #695
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
lazy config #695
Conversation
Hmm, so a downside of this approach is that if you don’t have any config file, every request requires materializing the default config (which includes crawling the docs folder to find all pages). That’s kind of a bummer. I’m not sure how to solve that… probably recording the current time before you load the config, and then invalidating the previously-cached config if any Markdown file within the root is newer than the last load time? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
want!
tested with #765 this works very well |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On my machine the preview server needs 1.1s to read the 300 pages of pangea. So that gives me an estimate of about 3ms per page. That's probably fine for medium-sized projects (of course for a large project you wouldn't rely on the default config).
However I noticed that a page that loads 20 _esm.js resources will pay this cost 20 times, so that's now 60ms per page. Even for a medium project this might add up to too much time.
But, I think it points to a simple optimization—pay this cost only once every few seconds. Adding a simple memoization of the result of readConfig completely fixes the issue instantly.
async _readConfig() {
const t = +new Date();
if (_mem.until > t) return _mem.config;
_mem.until = t + 12000;
return _mem.config = readConfig(this._config, this._root)
}
I don't think it's a blocker, and can be worked on as a follow-up.
I can take a look at memoizing just I’m surprised that _esm.js resources make a difference, though? |
I don't know exactly as I am only looking at the network tab in the inspector. Each resource served has the same ~1s latency. |
Ah, sure, that’s because each request to the preview server, including the linked resources, will load the config. |
The latest commit makes the default This feels nice! I think we could further add caching to |
This seems to have removed the memoization of the minisearch index. |
I don’t see that… but it is loading |
It does break the |
I've confirmed the problem with a brand-new clone of the repo: after this commit minisearch.json is now recreated every time, which makes the search slow in preview. Because it's memoized in a WeakMap indexed with the config:
To fix we could just memoize it independently of the config. But for now… good night! |
Fix in #1129! |
This defers loading of the config until a request is made, such that when the page is reloaded, we can always grab the latest config. This means you don’t have to restart the preview server in order to see config changes.
Fixes #645.
Fixes #646 (although, doesn’t push the change down — you still have to reload).