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

printf scientific notation performance regression #8972

Closed
simonster opened this issue Nov 11, 2014 · 8 comments
Closed

printf scientific notation performance regression #8972

simonster opened this issue Nov 11, 2014 · 8 comments
Assignees
Labels
kind:regression Regression in behavior compared to a previous version performance Must go faster
Milestone

Comments

@simonster
Copy link
Member

 function f()
    io = IOBuffer()
    for i = 1:100000
        @printf io "%e" 28.0
    end
end

On Julia 0.3:

julia> @time f()
elapsed time: 0.078705771 seconds (4195572 bytes allocated)

On Julia 0.4:

julia> @time f()
elapsed time: 2.91291863 seconds (290595572 bytes allocated, 45.76% gc time)

@profile suggests the time is spent in grisu's GMP codepath, so I'm guessing #7291 is the culprit. cc @quinnj

@simonster simonster added performance Must go faster kind:regression Regression in behavior compared to a previous version labels Nov 11, 2014
@simonster simonster changed the title printf performance regression printf scientific notation performance regression Nov 11, 2014
@quinnj
Copy link
Member

quinnj commented Nov 11, 2014

Hmmmm.......I'll try to look into it. A big difference here is that the double conversion library was rolling its own minimal BigInt, while grisu.jl utilized GMP. I believe some of their code makes use of reusing allocated BigInts, which we probably aren't and would explain all the extra allocation.

@simonster
Copy link
Member Author

It looks like the slow path is used for most (all?) integers, e.g.:

julia> function f(x)
          io = IOBuffer()
          for i = 1:100000
              @printf io "%e" x
          end
       end;

julia> @time f(1.)
elapsed time: 2.313745457 seconds (264195572 bytes allocated, 52.41% gc time)

julia> @time f(1.+eps())
elapsed time: 0.044512516 seconds (17819740 bytes allocated)

I haven't looked into the code to see how @printf uses grisu, but it seems like it should be possible to print integers in scientific notation without resorting to GMP.

@quinnj quinnj self-assigned this Dec 1, 2014
@JeffBezanson JeffBezanson added this to the 0.4 milestone Dec 5, 2014
@JeffBezanson
Copy link
Sponsor Member

Bump. This is pretty serious.

@quinnj quinnj modified the milestones: 0.4, 0.4.1 Feb 28, 2015
@quinnj
Copy link
Member

quinnj commented Mar 2, 2015

Status update: I've gotten a 5x improvement so far after a first pass. I'm still seeing some gc action in profiling so I'm going to keep digging.

@JeffBezanson
Copy link
Sponsor Member

Awesome, thanks.

@JeffBezanson
Copy link
Sponsor Member

@quinnj would it make sense to commit your 5x improvement? As it stands, this regression is probably bad enough to block 0.4.

@quinnj
Copy link
Member

quinnj commented Mar 6, 2015

I want to run the full grisu testing suite on my changes first; I'll make a PR tomorrow after it runs.

@quinnj
Copy link
Member

quinnj commented Mar 9, 2015

PR coming later tonight! (once I fix a few tests)

@quinnj quinnj closed this as completed in 724d754 Mar 10, 2015
quinnj added a commit that referenced this issue Mar 10, 2015
Add custom Bignum type for internal grisu performance. Fixes #8972
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:regression Regression in behavior compared to a previous version performance Must go faster
Projects
None yet
Development

No branches or pull requests

3 participants