<div dir="ltr">Hi ghc-devs,<br><br>I've been working on a new mode of adding cost-centres to programs and I'd<br>like to ask some questions and solicit some feedback. The code is here [fn:1],<br>it works, provided one enables -fprof-core on all modules.<br><br>I've recently been trying to pick some low hanging fruit from ghc compilation<br>performance. A common frustration was in the difference between profiled and<br>non-profiled builds. Often I thought had I found a problem in the profiled<br>build, only to find it was optimized away in the non-profiled build. Several<br>times an issue was tail-calls not happening in profiled builds.<br><br>To solve this problem I've been working on a new way of inserting cost-centres:<br>adding them to core after simplification (currently at the end of corePrepPgm)<br>rather than adding them to HsSyn before simplification. This makes it harder to<br>map cost-centres into source code (You have to -ddump-prep currently), but in<br>exchange you are profiling the same core program as the non-profilied build.<br><br>I intend to investigate whether I can use SourceNotes to create SrcSpans for the<br>generated cost-centres to somewhat alleviate the need to inspect dumped core.<br><br>There are several new flags:<br><br>-fprof-core: Enables the aforementioned mode. This is mutually exclusive with<br>-fprof-auto etc.<br><br>-fprof-core-drop-ticks: Non-user ticks are dropped from unfoldings(though I<br>  don't know how to do this yet).<br><br>-fprof-core-tick-binds: ticks are inserted around the RHS of bindings (except<br>  top-level unlifted bindings).<br><br>-fprof-core-tick-cases: ticks are inserted around the scrutinees of cases.<br><br>-fprof-core-tick-alts: ticks are inserted around Alt expressions (unless there<br>  is only one).<br><br>Some questions:<br><br>I need to strip (probably only non-user) ticks out of unfoldings before they are<br>substituted into a module that uses -fprof-core. Where is the right place to do<br>this? I need inlining to proceed exactly as if the ticks were not present,<br>however I don't want to strip ticks when the unfoldings are created as other<br>modules may still need them.<br><br>Is the end of corePrepPgm the right place to insert the cost-centres? I chose it<br>because it can't affect any core optimizations if it's last, but perhaps it<br>could be earlier, or perhaps it needs to act on Stg?<br><br>Do you have any examples of programs for which existing profiling tools are<br>inadequate due to how cost-centres affect simplification? There is an example in<br>#12893 but something self-contained would be great!<br><br>Regards,<br>Doug Wilson</div>