Merge: JSON Parser Optimization
authorJean Privat <jean@pryen.org>
Tue, 10 May 2016 14:32:32 +0000 (10:32 -0400)
committerJean Privat <jean@pryen.org>
Tue, 10 May 2016 14:32:32 +0000 (10:32 -0400)
commitea71df830cc9bc3b708a762d32903e83c34ce185
tree86fdc543c6693a18c41fe81b80deee57db0bd63e
parent0ec0f67efe80298301ee2d16c7f845edf7b2ba58
parent5c54927281840db0aac721ee83b6c692d37c239f
Merge: JSON Parser Optimization

This PR improves the speed of JSON parsing with the `string_parser` module. The new version of `parse_json_string` is heavily inspired by Python's implementation, available [here](https://github.com/python/cpython/blob/master/Modules/_json.c)

Time is usually either as performing as before or better, Valgrind also gives the new version an advantage, sometimes significant.

On `large_escaped` (~120M, lots of escaped characters), we have:

* Before: 13 748 436 458 Ir
* After: 11 687 104 643 Ir

i.e. an improvement of ~18%

Time is:
* Before: 0m4.428s
* After: 0m3.932s

i.e. an improvement of ~13%

Note that on this particular test, although the number of allocations is limited as much as we can, Boehm still cannibalizes the runtime, seeing that the real time is ~2.6s.
Perf gives a total time of ~38% in GC_mark and ~7% in GC_cache_miss.

Some more optimizations can be thought, but this shows how important a good GC is necessary for the future, this program can be a good metric of how GC usage can be improved.

For further reference, Python3 on the same test gives the following output on time and Valgrind:

* Time (user): 0m1.760s
* Time (real): 0m2.177s
* Valgrind: 8 845 966 867 Ir

Pull-Request: #2058
Reviewed-by: Jean Privat <jean@pryen.org>
lib/core/text/flat.nit