Efficiency for calling Julia from python and purely run Julia

Thank you for your reply. I apologize that I overlooked at your point about 2-3 ms. Now I suppose it is about the timing 2.769 ms (21 allocations: 6.18 MiB).. And I should have expressed clearer about my question. I thought about using a simple example. In the actual calculations, the timing for one set of permutation with addition is about 5 second. (there are many), more worthwhile to exploit than millisecond scale.

If I call julia from python directly, for a longer time calculation (larger dimension/larger rank of array/more permutations etc), the delay may be less important. For example, if I set na=80 in the python example on the top of the question and n_max = 2 to save time, I got

7.643103837966919
2.206459641456604
1.2286523580551147
python 1.7510950565338135

the third line of Julia is faster than python.

This implies I may not need system image/ C, C++ pointer or calling python from julia (the main python code has 1000+ lines, i think it would be a bit complicated to call from julia. I may try anyway).

But in this approach (call julia from python) performance somehow varies time to time. Let me exploit the direct calling julia approach and advanced approaches for a while.

EDITED:

julia --project=. --sysimage=my-sysimage.so mwe.jl

I can pass this step.

In calling from python, I replaced PATH/TO as my current directory, got
subprocess.CalledProcessError: Command '['/mnt/c/Users/.../my-sysimage.so', '-e', '...']' died with <Signals.SIGSEGV: 11>.

using lower API from python - Compile and use custom system image for PyJulia - Stack Overflow
after replaced the ‘PATH’ as my current directory, passed first 4 steps, in from julia import Main,
I got

Error processing line 1 of /home/.../python3.8/site-packages/google_auth-1.33.0-py3.9-nspkg.pth:

Fatal Python error: init_import_size: Failed to import the site module
Python runtime state: initialized
Traceback (most recent call last):
  File "/home/.../python3.8/site.py", line 169, in addpackage
    exec(line)
  File "<string>", line 1, in <module>
  File "/home/.../python3.8/importlib/util.py", line 14, in <module>
    from contextlib import contextmanager
  File "/home/.../python3.8/contextlib.py", line 5, in <module>
    from collections import deque
  File "/home/.../python3.8/collections/__init__.py", line 24, in <module>
    import heapq as _heapq
  File "/home/.../python3.8/heapq.py", line 581, in <module>
    from _heapq import *
SystemError: initialization of _heapq did not return an extension module

I vaguely recall previously the system asked about Project.toml etc, and I copied them to my current directory. I got it work once, but not anymore.
Sorry for bothering you time to time :frowning: