Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

further improvement to loading time #27

Open
thautwarm opened this issue Aug 11, 2022 · 2 comments
Open

further improvement to loading time #27

thautwarm opened this issue Aug 11, 2022 · 2 comments

Comments

@thautwarm
Copy link
Member

thautwarm commented Aug 11, 2022

As a Python user, one second loading time for a small project is painful.

I'm testing a very small example as follows:

module mylib
using TyPython
using TyPython.CPython

@export_py function sum_along_indices(array::Vector{Cdouble}, indices::Vector{Int32})::Cdouble
    s = zero(Cdouble)
    for i in indices
        s += array[i + 1]
    end
    return s
end


@export_py function add(a::Int, b::Int)::Int
    a + b
end


function init()
    @export_pymodule _mylib begin
        sum_along_indices = Pyfunc(sum_along_indices)
        add = Pyfunc(add)
    end
end

precompile(init, ())
end

This seems to be the theoretically fastest loading time:

julia> @time begin import Pkg, TyPython; TyPython.CPython.init()
       Pkg.activate("mylib"); import mylib; TyPython.CPython.init();mylib.init()
       end
  Activating project at `C:\Users\TR\Desktop\demo\mylib\mylib`
  0.973526 seconds (1.72 M allocations: 100.042 MiB, 2.27% gc time, 70.02% compilation time)
Py(namespace(sum_along_indices=<built-in function sum_along_indices>, add=<built-in function add>))

So far the extra overhead comes from the following parts, which can be optimized in the future:

  1. calling interpreted julia to get configuration:

    jnumpy/jnumpy/init.py

    Lines 112 to 117 in 669e046

    cmd = [
    SessionCtx.JULIA_EXE,
    jl_opts_proj,
    *jl_opts,
    "--startup-file=no",
    "-O0",

  2. calling interpreted julia to get the module name:

    jl_module_name = get_project_name_checked(project_dir)

@songjhaha
Copy link
Member

Using python's toml to parse a Project.toml would be better here:

jl_module_name = get_project_name_no_exc(project_dir)

It cost 0.1s to get project name while init_project() cost 0.9s on my computer.

@thautwarm
Copy link
Member Author

Fine, we could use toml at this stage.

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

No branches or pull requests

2 participants