3 ms·
I've noticed that instead of defining requires at the top of Lua files, if you can know your own program well enough, defining them right before the dependency
by andrewmcwatters 11mo ago
I've noticed that instead of defining requires at the top of Lua files, if you can know your own program well enough, defining them right before the dependency is actually used makes large Lua programs much, much quicker. Generally speaking, startup times can be a sped up by a meaningful factor.
I suspect this change in Python will dramatically improve the performance of such large programs as well.
- embedding-shape 11mo ago> I suspect this change in Python will dramatically improve the performance of such large programs as well. Makes packaging super fun too, where you need to hit every possible path so you don't miss anything imported in 1% of the execution paths :)
- snovv_crash 11mo agoCan't you do some kind of static analysis instead?
- fithisux 11mo agoYes. It is much more clear to be explicit though.
- jacquesm 11mo agoSafer too.
- Figs 11mo agoDepends if your code has horrors like this lurking in it: m = importlib.import_module(requests.get("http://localhost:8000/package_name").content.strip().decode("ASCII"))
- falcor84 11mo agoIf you want even better nightmares, you can make localhost:8000 forward to a container running claude code with --dangerously-skip-permissions which uses an unkindness of mcp servers to control that endpoint on the fly based (amongst other sources) on 4chan's /b/.
- snovv_crash 11mo agoBetter to let the viewers on a twitch stream vote for it.
- zahlman 11mo ago> which uses an unkindness of mcp servers I guess you meant "a feature of MCP servers which is unkind", but I couldn't help but interpret "unkindness" as the collective noun for a group of MCP servers.
- falcor84 11mo agoThat was indeed the intent. I first considered "a conspiracy" like with lemurs, but eventually felt that "unkindness" was more appropriate.
- im3w1l 11mo agoSince this should be a rare thing I don't think it's unreasonable to require users of patterns like this to put some kind of special annotation for that static analysis tool saying "it may not look like it but I'm doing an import here".
- KptMarchewa 11mo agoI can't even express how negatively I feel about build/packaging systems that process dependencies based on code-level imports instead of some explicit build manifest separate to the code.
- embedding-shape 11mo agoYou and me both, but life as a consultant/freelancer requires you to drag yourself through dirt sometimes to make it out on the other side.
- jacquesm 11mo agoNot to mention the potential for runtime errors long after the code has started up.
- dragonwriter 11mo agoOr, you could just use a project-level specification file to list dependencies rather than looking for imports in the code, trying to figure out what they resolve to, and trying to package the results.
- markrages 11mo agoYou have always been able to do the same thing in Python. This PEP isn't needed for that functionality.
- andrewmcwatters 11mo agoYeah, I'm aware the same behavior is available, but this proposal creates a call trigger on the dependency which requires far less analysis on larger projects to understand where the import needs to be moved to. You have to create wrappers in languages like JavaScript, Lua, Python, etc. to create the same behavior.
- skywhopper 11mo agoYou can declare imports at the beginning of a program that don’t load until they are used?
- markrages 11mo ago"defining them right before the dependency is actually used"
- deleted 11mo ago[deleted]