MiSawa / xq

Pure rust implementation of jq
MIT License
318 stars 18 forks source link

Compile only required prelude functions #99

Open itchyny opened 2 years ago

itchyny commented 2 years ago

Currently xq seems to compile all the prelude functions even if they are not needed. This is overhead as most prelude functions are not required in most use cases. Also, it would be useful when adding functions to prelude, if the order does not matter.

MiSawa commented 2 years ago

Yeah that'd be great. It might be not too hard to implement it by just making funcdefs register name, arg types and lazy-compiling function. Though allowing function calls to the functions defined below of it might be a bit more difficult, because it would require the caller of those lazily compiling functions to have a reference to a proper scope, and I'm not sure what scope would be proper :thinking:. If we'd do this disordered function resolving thing only on the module top level functions, that proper scope would be the scope at the end of the module compiling I guess. If we were to apply this to other function definitions.... I don't know, maybe we'd have to change parser to treat a chain of function definitions differently.

MiSawa commented 2 years ago

Actually I have a feeling that prelude functions should be compiled at the compile time in build.rs and embedded to the module loader.

itchyny commented 2 years ago

That would grow the executable size so it's trade-off between time and space.