Skip to content

Libptr by env#781

Open
cjdoris wants to merge 2 commits into
mainfrom
libptr-by-env
Open

Libptr by env#781
cjdoris wants to merge 2 commits into
mainfrom
libptr-by-env

Conversation

@cjdoris
Copy link
Copy Markdown
Member

@cjdoris cjdoris commented May 31, 2026

Pass the libptr in juliacall from Python to Julia with an env var instead of by setting a secret variable in Main.

We do this because we can set the env var earlier, in particular, so that PythonCall sees it even if it is loaded during jl_init(), which happens when PythonCall is baked into a system image.

I think this resolves the issue in #773.

@github-actions
Copy link
Copy Markdown
Contributor

Benchmark Results (Julia v1)

Time benchmarks
main 573d7b9... main / 573d7b9...
basic/@py/pydict/init 0.252 ± 0.051 ms 0.249 ± 0.048 ms 1.02 ± 0.28
basic/@py/pydict/pydel 0.254 ± 0.022 ms 0.257 ± 0.02 ms 0.99 ± 0.11
basic/julia/pydict/init 0.227 ± 0.071 ms 0.221 ± 0.071 ms 1.03 ± 0.46
basic/julia/pydict/pydel 0.237 ± 0.046 ms 0.231 ± 0.038 ms 1.03 ± 0.26
gc/full 0.597 ± 0.008 s 0.602 ± 0.007 s 0.991 ± 0.018
time_to_load 2.03 ± 0.0081 s 2.04 ± 0.01 s 0.994 ± 0.0064
Memory benchmarks
main 573d7b9... main / 573d7b9...
basic/@py/pydict/init 5.01 k allocs: 0.0764 MB 5.01 k allocs: 0.0764 MB 1
basic/@py/pydict/pydel 5.01 k allocs: 0.0764 MB 5.01 k allocs: 0.0764 MB 1
basic/julia/pydict/init 4.01 k allocs: 0.0612 MB 4.01 k allocs: 0.0612 MB 1
basic/julia/pydict/pydel 4.01 k allocs: 0.0612 MB 4.01 k allocs: 0.0612 MB 1
gc/full 0 allocs: 0 B 0 allocs: 0 B
time_to_load 0.145 k allocs: 0.26 MB 0.143 k allocs: 10.6 kB 25.1

@cjdoris
Copy link
Copy Markdown
Member Author

cjdoris commented May 31, 2026

@ncudlenco this PR changes how libptr is passed into julia from python, so it should now be picked up if PythonCall is inited during jl_init, which is the case when it is baked into a sysimage. Could you verify if this change is sufficient to use such a sysimage? I'm hopeful that this is an alternative to #773 that doesn't require any sysimage-specific handling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant