-
Notifications
You must be signed in to change notification settings - Fork 67
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 commands #151
Comments
One strategy would be to tweak the core so that the state machine starts small, and progressively expand as we find new tokens we don't know how to support. Let's say we have commands We'll now parse the following CLI input:
Things would go like this:
This approach allowed us to avoid having to make other calls than 4 filesystem calls. It however has a couple of thorny aspects:
In practice, doing this will require:
|
When writing large CLI application, we find ourselves in a pickle. Let's say we have commands similar to:
The
something
andsomethingElse
functions aren't needed untilMyCommand
is executed, but since they are in a top-level import the generated code will still import them before even evaluating the command file. At the scale of a large application, those imports start to slow down the startup by a significant factor. We can mitigate it a little by doing something like this:But that's really verbose, and that's not even what people doing things like this do (they instead just call
import
multiple times in a row, like top-level imports, except that it prevents the runtime from fetching / parsing the modules in parallel, making sync something that could be parallelized).A second problem is that even if the imports are moved into
execute
, just running files has a cost. They need to be read, parsed, evaluated, and all that when they don't actually contribute to anything at all for the purpose of the command parsing. This problem is exacerbated when using transpilers, as the cost can easily reach hundreds of ms for larger CLIs.The first point can be solved by the Deferring Module Evaluation proposal, but it's currently still at stage 2 (cc @nicolo-ribaudo in case you're interested by this thread / practical use case), and even with that we'd still have the problem of the files being executed at all (probably not as much a problem if you don't use a transpiler).
Ideally, I'd like to find a way to solve both points.
The text was updated successfully, but these errors were encountered: