Monday, July 7, 2008

Improving Performance

While looking over Mat's extensions to Ngaro I had a thought about inlining the handful of words which correspond to Ngaro instructions. A few tests showed enough promise that I've added a new .inline class to Retro.

The primitives will only be inlined if they are not revectored. This ensures that they will behave as closely to normal Forth words as possible. Devectoring a .inline word will restore the original behaviour. This is not intended for user code, and is only useful if you are adding new opcodes to your Ngaro VM.

Anyway, a look at the benchmarks:

Switched VM

Before:
- Recursive FIB (39)... 208.0144 seconds
- Countdown Loop (1,000,000)... 12.228482 seconds
- Nest/Unnest (256 million pairs)... 42.299306 seconds

Now:
- Recursive FIB (39)... 85.860101 seconds
- Countdown Loop (1,000,000)... 12.38329 seconds
- Nest/Unnest (256 million pairs)... 30.796164 seconds

Threaded VM

Before:
- Recursive FIB (39)... 130.537818 seconds
- Countdown Loop (1,000,000)... 8.325312 seconds
- Nest/Unnest (256 million pairs)... 27.092447 second
s

Now:
- Recursive FIB (39)... 51.989871 seconds
- Countdown Loop (1,000,000)... 8.292265 seconds
- Nest/Unnest (256 million pairs)... 17.577663 seconds

I'll update the documentation to cover the new class in the near future. If you don't want to wait for a new release, you can get this code from the GIT repository. See http://repo.or.cz/w/retro.git for details.

No comments: