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

slightly improve type instability and add a precompile statement #5

Merged
merged 2 commits into from
Oct 23, 2021

Conversation

KristofferC
Copy link
Contributor

@KristofferC KristofferC commented Apr 27, 2021

This package showed up in a profile trace I did when some packages where loaded.

Before:

julia> @time @eval vparse("v1.0.2");
  0.187844 seconds (371.28 k allocations: 21.236 MiB, 100.73% compilation time)

After:

julia> @time @eval vparse("v1.0.2");
  0.065536 seconds (4.64 k allocations: 253.828 KiB, 102.06% compilation time)

ccall(:jl_generating_output, Cint, ()) == 1 || return nothing
precompile(Tuple{typeof(VersionParsing.vparse), String})
end
_precompile_()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the advantage of this over calling precompile(...) unconditionally?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just seen everyone do it like this so it only runs when the package is precompiling (and not when it is loaded with e.g. --compiled-modules=no). But I could just do it like that if you prefer.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ccall'ing an undocumented internal function seems like a weird idiom to encourage.

Why isn't precompile just a no-op if --compiled-modules=no?

Copy link
Contributor Author

@KristofferC KristofferC May 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know. How do you want to proceed here?

Copy link

@timholy timholy Oct 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why isn't precompile just a no-op if --compiled-modules=no?

Because a few functions must be precompiled before you call them. A good example is anything that switches typeinference itself to a different implementation.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because a few functions must be precompiled before you call them. A good example is anything that switches typeinference itself to a different implementation.

It seems like those weird functions should be the ones doing undocumented internal ccalls, rather than forcing this idiom on everyone else…

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

precompile literally means "compile now without calling it." Technically, it bears no relation to --compiled-modules=no which has to do with whether you load code from *.ji files.

But if you hate this we can just delete it. There is essentially no cost and this discussion has already grown more expensive than that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the ccall.

ccall(:jl_generating_output, Cint, ()) == 1 || return nothing
precompile(Tuple{typeof(VersionParsing.vparse), String})
end
_precompile_()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But you might want to do this only for Julia 1.4.2 and higher. There are occasional segfaults on earlier versions.

@KristofferC
Copy link
Contributor Author

KristofferC commented Oct 17, 2021

Bump can this be merged? This is the standard way of doing it in every single package that provides precompile signatures. I think having this be consistent with the rest of the ecosystem is worth it over hacking in some other workaround that looks more "official".

@KristofferC
Copy link
Contributor Author

Friendly bump.

@stevengj stevengj merged commit 557df21 into JuliaInterop:master Oct 23, 2021
@KristofferC KristofferC deleted the kc/prec branch October 23, 2021 08:44
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.

3 participants