jlecomte/context-cache — pull request #2 by caridy (2013-01-26 19:07:31+00:00)
Title: adding isolation modes: clone, proto and json

Different strategies for isolation can cover different use cases. When it comes to extract data from the cache in isolation mode, the type of data to retrieve is key, that's why we should support different isolation modes.

In this PR I added a couple of benchmark tests to corroborate what we already knew:

```
+--------------------------+-------------------+----------------------+-----------------------+----------------------+
| | Simple object | 3 levels deep object | 10 levels deep object | Extremely big object |
+--------------------------+-------------------+----------------------+-----------------------+----------------------+
| get without isolation | 2,315,566 ops/sec | 2,298,742 ops/sec | 2,313,116 ops/sec | 2,317,961 ops/sec |
+--------------------------+-------------------+----------------------+-----------------------+----------------------+
| get with json isolation | 1,019,028 ops/sec | 933,075 ops/sec | 447,448 ops/sec | 3,810 ops/sec |
+--------------------------+-------------------+----------------------+-----------------------+----------------------+
| get with clone isolation | 808,036 ops/sec | 690,388 ops/sec | 270,860 ops/sec | 773,567 ops/sec |
+--------------------------+-------------------+----------------------+-----------------------+----------------------+
| get with proto isolation | 789,059 ops/sec | 261,269 ops/sec | 86,073 ops/sec | 352,577 ops/sec |
+--------------------------+-------------------+----------------------+-----------------------+----------------------+
```

This table give us some good insight:

* "get without isolation" is always the fastest, of course it is!
* "get with proto isolation" seems to be pretty slow in most cases, except when it comes to objects with few members, but strings.
* "get with json isolation" is the best we can get except when it comes to objects with big strings, probably because of the buffer allocation.
* "get with clone isolation" is not that far from "json", and it seems to work really well for objects with big strings. I guess the buffer references help when copying an object.

Bottom-line, it is all about clone vs json mode, depending on the data you will store and retrieve.