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

Propagate iteration info to optimizer #36684

Merged
merged 1 commit into from
Jul 18, 2020
Merged

Propagate iteration info to optimizer #36684

merged 1 commit into from
Jul 18, 2020

Commits on Jul 17, 2020

  1. Propagate iteration info to optimizer

    This supersedes #36169. Rather than re-implementing the iteration
    analysis as done there, this uses the new stmtinfo infrastrcture
    to propagate all the analysis done during inference all the way
    to inlining. As a result, it applies not only to splats of
    singletons, but also to splats of any other short iterable
    that inference can analyze. E.g.:
    
    ```
    f(x) = (x...,)
    @code_typed f(1=>2)
    @benchmark f(1=>2)
    ```
    
    Before:
    ```
    julia> @code_typed f(1=>2)
    CodeInfo(
    1 ─ %1 = Core._apply_iterate(Base.iterate, Core.tuple, x)::Tuple{Int64,Int64}
    └──      return %1
    ) => Tuple{Int64,Int64}
    
    julia> @benchmark f(1=>2)
    BenchmarkTools.Trial:
      memory estimate:  96 bytes
      allocs estimate:  3
      --------------
      minimum time:     242.659 ns (0.00% GC)
      median time:      246.904 ns (0.00% GC)
      mean time:        255.390 ns (1.08% GC)
      maximum time:     4.415 μs (93.94% GC)
      --------------
      samples:          10000
      evals/sample:     405
    ```
    
    After:
    ```
    julia> @code_typed f(1=>2)
    CodeInfo(
    1 ─ %1 = Base.getfield(x, 1)::Int64
    │   %2 = Base.getfield(x, 2)::Int64
    │   %3 = Core.tuple(%1, %2)::Tuple{Int64,Int64}
    └──      return %3
    ) => Tuple{Int64,Int64}
    
    julia> @benchmark f(1=>2)
    BenchmarkTools.Trial:
      memory estimate:  0 bytes
      allocs estimate:  0
      --------------
      minimum time:     1.701 ns (0.00% GC)
      median time:      1.925 ns (0.00% GC)
      mean time:        1.904 ns (0.00% GC)
      maximum time:     6.941 ns (0.00% GC)
      --------------
      samples:          10000
      evals/sample:     1000
    ```
    
    I also implemented the TODO, I had left in #36169 to inline
    the iterate calls themselves, which gives another 3x
    improvement over the solution in that PR:
    
    ```
    julia> @code_typed f(1)
    CodeInfo(
    1 ─ %1 = Core.tuple(x)::Tuple{Int64}
    └──      return %1
    ) => Tuple{Int64}
    
    julia> @benchmark f(1)
    BenchmarkTools.Trial:
      memory estimate:  0 bytes
      allocs estimate:  0
      --------------
      minimum time:     1.696 ns (0.00% GC)
      median time:      1.699 ns (0.00% GC)
      mean time:        1.702 ns (0.00% GC)
      maximum time:     5.389 ns (0.00% GC)
      --------------
      samples:          10000
      evals/sample:     1000
    ```
    
    Fixes #36087
    Fixes #29114
    Keno committed Jul 17, 2020
    Configuration menu
    Copy the full SHA
    984c504 View commit details
    Browse the repository at this point in the history