←back to thread

196 points bovem | 3 comments | | HN request time: 0.619s | source
Show context
upbeat_general ◴[] No.41147186[source]
Does this have faster startup times than cpython?

Every time I want to rewrite a shell function in python, I always hesitate due to the slow startup.

replies(2): >>41147958 #>>41151966 #
actinium226 ◴[] No.41147958[source]
How fast does it really need to be? On my M2 macbook air:

    $ time A=1 B=1 python -c "import os; print(int(os.getenv('A'))+int(os.getenv('B')))"
    2

    real 0m0.068s
    user 0m0.029s
    sys 0m0.026s
replies(1): >>41147986 #
1. wredue ◴[] No.41147986[source]
Eh. Once you start using imports, python slows down dramatically.

So I guess it really just depends what your scripts use.

replies(1): >>41148566 #
2. KolenCh ◴[] No.41148566[source]
Regarding import cost, as it’s doing heavy IO traversing the file system, the cost heavily depends on how fast you can do IO in the hardware, and also the file system (and the OS).

So a fast SSD will help, and somewhat surprisingly putting it inside docker helps (in an HPC context, not so sure it’s implications here as we’re talking about a short scripts.)

But the context here is to port shell scripts to Python, I’m not sure how huge amounts of imports matters.

And it is probably an intrinsic problem of the language, unless we start talking about compiling (and somehow statically) not interpreting the Python program, whichever implementation of the language probably won’t help the situation.

Lastly, if high startup costs of the script becomes relevant, perhaps it is orchestrating wrong. This is an infamous problem of Julia, and their practice is then just keep the Julia instance alive and use it as “the shell”. Similarly, you can do so in Python. Ie rather than calling a script from the shell acting on millions of things, write a wrapper script that start the Python instance once. Memory leak could be a problem if it or its dependencies are not well written but even in that case you have ways to deal with that.

replies(1): >>41167304 #
3. wredue ◴[] No.41167304[source]
>But the context here is to port shell scripts to Python, I’m not sure how huge amounts of imports matters.

Never question the modern developers ability to import 1500 heavy libraries to accomplish something that only takes 10 lines of code.