Changes between Version 1 and Version 2 of PerformanceWarnings


Ignore:
Timestamp:
Oct 2, 2010 5:40:24 PM (4 years ago)
Author:
dons
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • PerformanceWarnings

    v1 v2  
    44 
    55The goal of this project is to have GHC guide the user to better performance, by warning of coding patterns that won't yield good performance. 
     6 
     7== Approach == 
     8 
     9Users have trouble understanding how strictness analysis works, how demand analysis works, when and why things are specialized, inlined or unboxed. Our goal is for the compiler to tell them when such things happen, in order to guide them to better code. 
     10 
     11== Stage 1: Performance Lint == 
     12 
     13=== Strictness Warnings === 
     14 
     15Users often feel a shotgun approach to strictness is the only way to fix performance or space problems. Due to difficulties reasoning about demand, a scattergun approach -- dropping bang patterns everywhere -- is used to squash laziness issues. This is usually unnecessary, and may make programs slower, than placing the getting the strictness precisely right. 
     16 
     17'''The compiler should warn about unnecessary uses of bang patterns or seq.''' 
     18 
     19=== Heuristics for "Probably a Performance Bug" === 
     20 
     21Atomic types: 
     22 
     23 * Int, Word, Int*, Word* 
     24 * Double, Float 
     25 
     26should almost always be unboxed in users' code. It is exceedingly rare for such values to be necessarily lazy for correctness. However, due to insufficient strictness, such types are often inferred as lazy, and consequently not unboxed.  
     27 
     28We can improve users' code by warning of any boxed types as arguments, or in data structures, for these types. Particularly accumulating parameters, or fields in record types. Additionally, if they are strict, but not unboxed, that should also be a warning. 
     29 
     30=== Other heuristics === 
     31 
     32 * Warning any use of >>= that doesn't inline 
     33 * Warn about lazy state monads 
     34 * Warn about lazy tuples 
     35 
     36== Output format == 
     37 
     38We could emit warnings about line / col number of values that "probably should be strict" or "have unnecessary bang patterns". 
     39 
     40A more advanced option would be to reuse -fhpc to emit colorized source. 
     41 
     42== Assertions == 
     43 
     44Once we can spot problems, the user could assert, via ANNOTATIONs, that particular properties must hold. These could trigger -Werrors. 
     45 
     46== Results == 
     47 
     48Results for quality of the warnings can be measured: 
     49 
     50 * Apply -fwarn-performance to a program 
     51 * Do what it says 
     52 * Measure the speedup. 
     53 
     54== Implementation == 
     55 
     56Add a -fwarn-performance flag that does two things: 
     57   
     58 * unnec. bang patterns/seq after strictness analysis 
     59 * uses a library of heuristics (programmable?) to lint-check core. 
     60 * The pass would be a core-to-warnings pass.