Other languages
Computer Science
Meta
The first step when optimizing Factor code is to ensure that it is compiled with the Optimizing compiler. A word will be optimized if and only if it has a static stack effect. To check this,
[ my-word ] infer.
You can define unit tests which assert this is true,
\ my-word must-infer
To see how the high level optimizer treats a word, you can use the following tool:
USE: compiler.tree.debugger \ foo optimized.
You will be able to see if generic dispatch has been eliminated, and if generic airthmetic has been converted to machine arithmetic, and which words have been inlined.
You can also pass a quotation to optimized.
:
[ 100 [ ] times ] optimized.
The high level compiler can be given hints and inline declarations which affects the output of the above.
To see how the low level optimizer treats a word,
USE: compiler.cfg.debugger \ foo test-mr mr.
To see the final code generated for a word, use the disassemble
word.
Disassembling words is accomplished using libudis86
on x86, and gdb
on PowerPC.
Note that udis
needs to be compiled with the --enable-shared
option:
extra/benchmarks/
directory. These programs are extremely optimized, but also written in a high-level style.fixnum+
, and so on. Given the right set of inlining declarations and hints, the compiler can eliminate generic arithmetic, and the result will be safer and more readable than if you attempt these transformations by hand.map
, reduce
, or something like that instead, since they already use unsafe operations under the hood.This revision created on Sun, 25 Jan 2009 00:46:17 by slava