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

Invalidations from constructor of Int64 #11

Closed
mateuszbaran opened this issue Sep 16, 2020 · 4 comments
Closed

Invalidations from constructor of Int64 #11

mateuszbaran opened this issue Sep 16, 2020 · 4 comments

Comments

@mateuszbaran
Copy link

In issue JuliaArrays/ArrayInterface.jl#61 (comment) there is some discussion about using StaticNumbers in other packages and one issue that was raised are increased compiled times. SnoopCompile let me quickly nail it down to overloading the constructor of Int64 from Static. Just removing it has a huge effect on load times:

➜  julia git:(master) ./julia -O3 -e "@time using StaticNumbers, ArrayInterface"
Loaded startup
  1.302702 seconds (976.64 k allocations: 54.788 MiB, 0.62% gc time)
➜  julia git:(master) ./julia -O3 -e "@time using StaticNumbers, ArrayInterface"
Loaded startup
  0.267415 seconds (160.44 k allocations: 11.461 MiB)

That's on a freshly deved StaticNumbers and after removing just that one method.

I don't know how critical that constructor is to functionality of StaticNumbers.jl.

@perrutquist
Copy link
Owner

Interesting. That constructor is very useful, however, as it is the most obvious way to make a number non-static. It would be possible to use a syntax like convert(Int, x) or unstatic(x) instead, but I really like the simplicity of Int(x).

A MWE to reproduce the problem is:

using SnoopCompile
struct MyType <: Integer end
@snoopr Base.Int64(::MyType) = 42

which yields a list of over 2000 invalidated methods.

Maybe the best solution would be to not make StaticInteger a subtype of Integer.

Related: I am planning to move the integers out of StaticNumbers, into a StaticIntegers package. That should also reduce compile time.

@perrutquist
Copy link
Owner

OK, so it seems Julia has a bunch of methods that are compiled for Integer at a point when Integer only contains Core.BuiltinInts. These methods typically convert to Int using the constructor. Extending the Int constructor to accept any other Integer type invalidates all those methods.

But I want to be able to call those methods with a static input, so StaticInteger has to be an Integer and there has to be an Int constructor from it.

Not sure how to solve this.

@mateuszbaran
Copy link
Author

I won't suggest any solution here since I'm not working on static numbers myself, but maybe you will be able to figure something out 🙂 .

@perrutquist
Copy link
Owner

There has been drastic improvement on the julia master branch recently. The above example that generated 2219 invalidations on 1.6.0-DEV.923 two weeks ago yields only 321 invalidations today on 1.6.0-DEV.1106. Unique invalidations dropped from 625 to 39.

The solution here seems to be to simply wait for Julia 1.6 to be released. Huge thanks to everyone on the julia team that has been working on this.

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