hippyvm/hippyvm — pull request #61 by vext01 (2014-08-29 11:17:36+00:00)
Title: Optimise immut cache for cache misses.

Hi,

The following diff optimises Hippy's immutible cache with respect to cache misses. This is achieved by "versioning" the immutable cache and promoting the version attribute when a cell is retrieved. This allows us to build traces in which the contents of the cache can be considered constant. We also return None instead of raising in the case of a cell not existing, since exception handling (so I am told) gets in the way of the tracer/JIT.

The majority of the was undertaken by Laurence Tratt. I only wrote more tests and benchmarked.

The motivation behind this work is mostly for the PyPy bridge in which we frequently see cache misses (because we are looking up a Python variable which will not be in the PHP cache). However, there are cases in PHP where this change can improve performance.

Consider the following program:

```

```

The program is continually causing global_function_cache misses.

Before the change:

```
===> multitime results
1: ./hippy-c-vanilla /home/vext01/research/vext01.pypy_bridge_examples/err.php 500000000
Mean Std.Dev. Min Median Max
real 15.641 0.067 15.600 15.611 15.775
user 15.612 0.070 15.573 15.577 15.753
sys 0.006 0.004 0.000 0.008 0.012
```

And after:

```
===> multitime results
1: ./hippy-c-immut-cache-opt /home/vext01/research/vext01.pypy_bridge_examples/err.php
+500000000
Mean Std.Dev. Min Median Max
real 1.949 0.003 1.944 1.949 1.954
user 1.941 0.003 1.936 1.940 1.944
sys 0.004 0.004 0.000 0.004 0.008
```

So that is a pretty decent speedup.

We also checked that programs that do not regularly miss the cache are not impacted. Here are measurements against the Richard's benchmark:

Before:
```
===> multitime results
1: ./hippy-c-vanilla /home/vext01/research/vext01.pypy_bridge_examples/richards/richards-vanilla.php 3000
Mean Std.Dev. Min Median Max
real 11.253 0.020 11.216 11.264 11.270
user 11.214 0.027 11.165 11.229 11.237
sys 0.020 0.007 0.012 0.016 0.032
```

After:
```
===> multitime results
1: ./hippy-c-immut-cache-opt /home/vext01/research/vext01.pypy_bridge_examples/richards/richards-vanilla.php 3000
Mean Std.Dev. Min Median Max
real 11.242 0.035 11.199 11.235 11.301
user 11.206 0.029 11.173 11.205 11.253
sys 0.018 0.008 0.008 0.016 0.032
```

So looks pretty good. What do you guys think?

All tests in `testing/` passing.

P.S.

I think I can tidy up the existing `immut_cache.py` tests a bit, but I will make a separate pull later.