Skip to content

Precompile the first calls of a JuliaCall session - #837

Open
MilesCranmerBot wants to merge 1 commit into
JuliaPy:mainfrom
MilesCranmerBot:precompile-first-call
Open

MilesCranmerBot wants to merge 1 commit into
JuliaPy:mainfrom
MilesCranmerBot:precompile-first-call

Conversation

@MilesCranmerBot

@MilesCranmerBot MilesCranmerBot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Python reaches pyjlany_getattr and pyjlmodule_seval through _pyjl_callmethod, which looks them up in PYJLMETHODS at runtime. Precompiling PythonCall therefore never compiled them, and every new JuliaCall session compiled them on its first jl.<name> or jl.seval(...). This PR adds a precompile statement for each.

First call in a fresh Python process (median of 8, Apple M1 Pro, PYTHON_JULIACALL_HANDLE_SIGNALS=yes):

Julia first call main this PR
1.11.9 jl.VERSION 0.43 s 0.016 s
1.11.9 jl.seval("1 + 1") 0.49 s 0.10 s
1.12.7 jl.VERSION 0.96 s 0.010 s
1.12.7 jl.seval("1 + 1") 0.97 s 0.067 s

Julia tests pass locally on 1.11.9 (3517 passed, 3 broken).

A new JuliaCall session usually starts with `jl.<name>` on `juliacall.Main` or `jl.seval(...)`. PythonCall's package image had no compiled code for either method, so every session compiled them at runtime, which took about a second.

Co-authored-by: Miles Cranmer <miles.cranmer@gmail.com>
@MilesCranmer

Copy link
Copy Markdown
Contributor

@cjdoris so this was a surprisingly decent improvement to startup time

This branch has not been deployed

No deployments
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.

2 participants