Optimise known type dictionaries
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Mars |
Fix Committed
|
Wishlist
|
Matt Giuca |
Bug Description
Using the 'show' and 'eq' functions (since we added type dictionaries) is taking a huge performance hit. This is because to call 'show' or 'eq', you now need to find the type dictionary for the type in question (a CGC, which requires evaluation), then do a lookup of the method in the dictionary (costly), and then call the method dynamically (inefficient).
For example, inside the 'ge' function is a call to 'eq' for integers. The generated assembly code (partial) is this:
$T:0:4 = ~@dict:Int
$T:0:3 = @:Dict:
$T:0 = $T:0:3($T:0:1, $T:0:2)
Note that the first line is evaluating a CGC (call to a function or a thunk lookup), and the second line features an entire call to another function (which will be efficiently inlined in LLVM, but still, this is a method lookup). Even in fully-optimised LLVM, this still needs to evaluate a thunk, dereference a pointer, pull a function pointer out of it, then call it indirectly.
For known type dictionaries, this should be replaced with a simple reference to the method:
$T:0 = @eq:Int($T:0:1, $T:0:2)
Related branches
Changed in mars: | |
milestone: | none → 1.0 |
Fixed in trunk r1355.