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

Isolate string interpolation in error paths for sparse matrix construction #38446

Merged
merged 1 commit into from
Nov 25, 2020

Conversation

timholy
Copy link
Sponsor Member

@timholy timholy commented Nov 15, 2020

This provides a better-than-3x speed improvement for spzeros(5, 5):

julia> @btime spzeros(5, 5);
  341.371 ns (3 allocations: 288 bytes)

julia> Revise.track(SparseArrays)

julia> @btime spzeros(5, 5);
  103.633 ns (3 allocations: 288 bytes)

…ctors

This provides a better-than-3x speed improvement for `spzeros(5, 5)`:

julia> @Btime spzeros(5, 5);
  341.371 ns (3 allocations: 288 bytes)

julia> Revise.track(SparseArrays)

julia> @Btime spzeros(5, 5);
  103.633 ns (3 allocations: 288 bytes)
@simeonschaub
Copy link
Member

I wonder whether we should have an @throw macro that just expanded to (() -> throw(...))(), which would make it easier to use this trick in more places.

@jmert
Copy link
Contributor

jmert commented Nov 15, 2020

The @lazy_str construct from #33711 is also a useful alternative to an @throw construct.

@PallHaraldsson
Copy link
Contributor

@timholy I like how this is faster, but I would worry about it staying that way, in (current or) future versions, e.g. e.g. -O3. I had such a case, and used @noinline, but I wish Julia would outline throw by default, so we wouldn't have to use tricks all over the place. Here (and I guess with proposed @throw trick) a future compiler could decide to inline and negate your optimization?

@timholy timholy closed this Nov 25, 2020
@timholy timholy reopened this Nov 25, 2020
@timholy
Copy link
Sponsor Member Author

timholy commented Nov 25, 2020

a future compiler could decide to inline and negate your optimization?

We have tests for throw paths, so hopefully that won't happen.

@timholy timholy merged commit 4b739e7 into master Nov 25, 2020
@timholy timholy deleted the teh/sparse_construct branch November 25, 2020 16:33
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.

None yet

4 participants