-
-
Notifications
You must be signed in to change notification settings - Fork 801
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
blitz console
is slow to load - switch to esbuild loader
#1098
Comments
Tried replicating this on Mac OS Catalina 10.15.6, but it worked without any perceivable delay. Here is sc of the time taken for each module: I know these times would vary between PCs and OS. Maybe it would be good to add a loading indicator when it is loading these modules. Let me know what you think @flybayer. |
@JoseRFelix thanks for investigating! This is definitely WAY better in the latest blitz canary. That said, I'm still noticing a 1-3s delay on my project which has a good bit more modules than what you listed here. I still think we should lazy load these, because as apps get bigger, this will get worse, no matter how optimized it is. |
So, I've been thinking about some possible solutions:
In my opinion, I would prefer to have the first option since all modules will be available on the get-go. |
Isn't it possible to keep what we have no (load everything), but set proxy objects in the repl context and when the proxy is accessed, load the requested module at that time. So by default Make sense? |
Yes, it is possible! The only thing to think about is how the script will know which file to import. This can work fine if we had the same file name and a single function per file. However, users can change the function name or have several functions that won't match the file name. Maybe, we could store every function name and validate it in the proxy. |
Yeah, but we have that same issue already, right? (you are right that we need to resolve that somehow) |
I'd say it could be a little bit faster than our current approach since we wouldn't be doing a full import. However, we still would have read the file to get every function name and search our object if it contains the function. |
Ok, if you want you can work on this and just figure out what makes the most sense to do. |
Sure! 🚀 |
@JoseRFelix I discovered that the console is quite fast when running the local blitz dev version, but it's still extremely slow when using off npm |
So I think a good solution is to use esbuild. Perhaps with https://github.com/egoist/esbuild-register or https://github.com/folke/esbuild-runner. I tried doing setting that up briefly. It certainly has potential but we need ability to provide custom esbuild options for things like setting Adding the "register" statement in our code is simple, same as we are currently doing with ts-node: https://github.com/blitz-js/blitz/blob/canary/packages/cli/src/utils/setup-ts-node.ts#L8 Note: one thing that's important is that this uses baseUrl and path aliases from both tsconfig.json and jsconfig.json |
blitz console
is very slow to load - need to lazy load app codeblitz console
is slow to load - switch to esbuild loader
So I gather that these are examples of runners/watchers for development mode. For using a bit of esbuild to build in production, to get ~2x build speedup with NextJS, try esbuild-loader-examples. |
What is the problem?
Starting
blitz console
has a long hangup time after "Loading your Code" is finished and before you can start typing.It gets much worse as you add more queries and mutations.
Steps to Reproduce
blitz new myapp
cd myapp
blitz g resource project
blitz g resource task
blitz g resource comment
blitz db migrate
blitz console
>
prompt appears. Notice that you can't type for a bit of time.Other
The main problem is
loadBlitz
, which for some reason is super slow on first start. Running.reload
after initial start (which re-runs loadBlitz) is quite fast.You can add a log statement here and see how slow it is for each module.
We are already using a lazy require loader which apparently isn't working here.
Probably we need to add a proxy object for each dependency, that only loads the module when it's accessed. But maybe there's a better way.
Update April 2021
See #1098 (comment)
The text was updated successfully, but these errors were encountered: