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

lazy LibGit2 initialization #28113

Merged
merged 1 commit into from
Jul 17, 2018
Merged

lazy LibGit2 initialization #28113

merged 1 commit into from
Jul 17, 2018

Conversation

StefanKarpinski
Copy link
Member

@StefanKarpinski StefanKarpinski commented Jul 13, 2018

I did this the lazy way but it seems to work fine. The right way would be to put a REFCOUNT[] == 0 && initialize() at the top of every function that calls into the libgit2 library. @JeffBezanson, does this get rid of that 0.1s of startup you were seeing on your system?

@ararslan ararslan added the libgit2 The libgit2 library or the LibGit2 stdlib module label Jul 13, 2018
@@ -972,12 +972,12 @@ function set_ssl_cert_locations(cert_loc)
Cint(Consts.SET_SSL_CERT_LOCATIONS), cert_file, cert_dir)
end

function __init__()
@check ccall((:git_libgit2_init, :libgit2), Cint, ())
function initialize()
REFCOUNT[] = 1
Copy link
Member

Choose a reason for hiding this comment

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

Threads.atomic_cas!(REFCOUNT, 1) == 0 || return?

Copy link
Member Author

Choose a reason for hiding this comment

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

The one and only call to it does the check. If I put the call in more places I'd factor it this way.

Copy link
Member

Choose a reason for hiding this comment

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

That check doesn't have the atomic_cas!. I don't particularly know why this is using thread-safe primitives right now, but that's how the code is written, so it seems like we are supposed to carry that through all of the say

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, I see what you're getting at. The old __init__ didn't bother since it's presumed that there's no raciness at startup but later on there could be. Sure, may as well respect the existing thread-safety.

@@ -972,12 +972,12 @@ function set_ssl_cert_locations(cert_loc)
Cint(Consts.SET_SSL_CERT_LOCATIONS), cert_file, cert_dir)
end

function __init__()
@check ccall((:git_libgit2_init, :libgit2), Cint, ())
function initialize()
Copy link
Member

Choose a reason for hiding this comment

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

might be worth adding @noinline here, since the compiler might see this is small enough to be feasible to inline, (even though that'll make us generate worse code)

@JeffBezanson JeffBezanson added the compiler:latency Compiler latency label Jul 13, 2018
@JeffBezanson
Copy link
Member

Yes, this helps a lot!

@StefanKarpinski
Copy link
Member Author

Yes, this helps a lot!

By how much? Any measurements?

@JeffBezanson
Copy link
Member

For me it reduces the time for ./julia -e 0 by 80-100ms.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:latency Compiler latency libgit2 The libgit2 library or the LibGit2 stdlib module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants