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

revisit #47137: avoid round-trip of locally-cached inferred source #51960

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

aviatesk
Copy link
Member

Built on top of #51958, with the improved performance of cfg_simplify!, let's give another try on #47137. Tha aim is to retain locally cached inferred source as IRCode, eliminating the need for the inlining algorithm to round-trip it through CodeInfo representation.

@nanosoldier runbenchmarks("inference", vs=":master")

@aviatesk aviatesk requested a review from Keno October 31, 2023 17:20
@aviatesk aviatesk added the compiler:optimizer Optimization passes (mostly in base/compiler/ssair/) label Oct 31, 2023
@nanosoldier
Copy link
Collaborator

Your job failed.

@aviatesk
Copy link
Member Author

@nanosoldier runbenchmarks("inference", vs=":master")

@nanosoldier
Copy link
Collaborator

Your job failed.

@vtjnash
Copy link
Member

vtjnash commented Oct 31, 2023

FWIW, you are running into an optimizer bug it seems

      From worker 2:    ERROR: LoadError: MethodError: no method matching string(::Expr)                                                                                                          
      From worker 2:                                                                                                                                                                              
      From worker 2:    Stacktrace:                                                              
      From worker 2:       [1] macro expansion                                                                                                                                                    
      From worker 2:         @ Core.Compiler ./error.jl:231 [inlined]                            
      From worker 2:       [2] process_node!(compact::Core.Compiler.IncrementalCompact, result_idx::Int64, inst::Core.Compiler.Instruction, idx::Int64, processed_idx::Int64, active_bb::Int64, do
_rename_ssa::Bool)                              
      From worker 2:         @ Core.Compiler ./compiler/ssair/ir.jl:1348                         
      From worker 2:       [3] cfg_simplify!(ir::Core.Compiler.IRCode)                           
      From worker 2:         @ Core.Compiler ./compiler/ssair/passes.jl:2275                     
      From worker 2:       [4] finish!(interp::Core.Compiler.NativeInterpreter, caller::Core.Compiler.InferenceState)                                                                             
...
      From worker 2:     [100] loadall!()
      From worker 2:         @ BaseBenchmarks /home/nanosoldier/.julia/dev/BaseBenchmarks/src/BaseBenchmarks.jl:52
      From worker 2:    in expression starting at /home/nanosoldier/.julia/dev/BaseBenchmarks/src/collection/CollectionBenchmarks.jl:1
      From worker 2:    in expression starting at /home/nanosoldier/.julia/scratchspaces/89f34f1a-2e6b-52eb-a20f-77051b03b735/workdir/jl_5yuKNX/benchscript.jl:18
┌ Info: [Node 2 | 2023-10-31T14:10:04.615]: failed job: BenchmarkJob JuliaLang/julia@a79443e vs. JuliaLang/julia@f631597

@aviatesk aviatesk mentioned this pull request Nov 1, 2023
@aviatesk aviatesk force-pushed the avi/opt-cfg_simplify! branch 2 times, most recently from 5f71c22 to 5152327 Compare November 5, 2023 04:14
Base automatically changed from avi/opt-cfg_simplify! to master November 6, 2023 01:44
aviatesk added a commit that referenced this pull request Nov 6, 2023
…sult (#51934)

Currently the inlining algorithm is allowed to use inferred source of
const-prop'ed call that is always locally available (since const-prop'
result isn't cached globally). For non const-prop'ed and globally cached
calls, however, it undergoes a more expensive process, making a
round-trip through serialized inferred source.

We can improve efficiency by bypassing the serialization round-trip for
newly-inferred and globally-cached frames. As these frames are never
cached locally, they can be viewed as volatile. This means we can use
their source destructively while inline-expanding them.

The benchmark results show that this optimization achieves 2-4% 
allocation reduction and about 5% speed up in the real-world-ish 
compilation targets (`allinference`).

Note that it would be more efficient to propagate `IRCode` object
directly and skip inflation from `CodeInfo` to `IRCode` as experimented
in #47137, but currently the round-trip through
`CodeInfo`-representation is necessary because it often leads to better
CFG simplification while `cfg_simplify!` being expensive (xref: #51960).
@aviatesk aviatesk mentioned this pull request Nov 7, 2023
@aviatesk aviatesk force-pushed the avi/47137-again branch 2 times, most recently from 1b97766 to 5af6b22 Compare November 10, 2023 01:01
@aviatesk
Copy link
Member Author

@nanosoldier runbenchmarks("inference", vs=":master")

@nanosoldier
Copy link
Collaborator

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here.

@aviatesk
Copy link
Member Author

@nanosoldier runbenchmarks("inference", vs=":master")

@nanosoldier
Copy link
Collaborator

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here.

@aviatesk aviatesk force-pushed the avi/47137-again branch 2 times, most recently from a77dd0c to 7050b4e Compare November 22, 2023 16:55
@aviatesk
Copy link
Member Author

@nanosoldier runbenchmarks("inference", vs=":master")

@nanosoldier
Copy link
Collaborator

Your job failed.

Built on top of #51958, with the improved performance of `cfg_simplify!`,
let's give another try on #47137. Tha aim is to retain
locally cached inferred source as `IRCode`, eliminating the need for the
inlining algorithm to round-trip it through `CodeInfo` representation.
@aviatesk
Copy link
Member Author

@nanosoldier runbenchmarks("inference", vs=":master")

@nanosoldier
Copy link
Collaborator

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:optimizer Optimization passes (mostly in base/compiler/ssair/)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants