Ruby xAP Parser Speed Improved by 28x

As I mentioned in a previous blog post, the latset version of the Depth Camera Controller firmware has been showing performance problems in its xAP parser.  Since then I've written a simplified parser that doesn't rely on Treetop, which runs over 28 times faster than the Treetop-based parser.  The new parser is a single method:

The complete updated version of xap_ruby, including the new parser, is available on Github. Benchmarks follow.

updated parser - x64

$ ./parser_bench.rb 10000
Running 10000 iterations of ParseXap.simple_parse
10000 iterations: cpu=0.360000 clock=(0.363838)
27484.72689933285 per second

Running 10000 iterations of ParseXap.parse
10000 iterations: cpu=10.640000 clock=(10.647138)
939.2195243898797 per second

Running 10000 iterations of node.to_hash
10000 iterations: cpu=0.280000 clock=(0.279407)
35790.08087596572 per second

updated parser - ARM

$ ./parser_bench.rb 1000
Running 1000 iterations of ParseXap.simple_parse
1000 iterations: cpu=0.800000 clock=(1.048829)
953.4446317047145 per second

Running 1000 iterations of ParseXap.parse
1000 iterations: cpu=21.990000 clock=(29.733424)
33.63218476814936 per second

Running 1000 iterations of node.to_hash
1000 iterations: cpu=0.720000 clock=(0.837403)
1194.1684162215195 per second


It appears that using a generic parser backend like Treetop is disadvantageous for simple parsing tasks like the xAP protocol. The upside of the Treetop-based parser is that it provides full validation of the message syntax, with better error messages for invalid xAP messages. This new parser will allow development of the Depth Camera Controller's web interface to continue.