basho/riak_cs — pull request #674 by kellymclaughlin (2013-09-13 23:04:23+00:00)
Title: Address performance issues when exporting XML documents

Address the repeated calls to `error_handler:undefined_function` that results in a call to the code_server and is a performance bottleneck. This commit adds a dependency on a [fork](https://github.com/kellymclaughlin/xmerl) of the `xmerl` library extracted from the OTP bundle. This fork has been modified so that a default callback function (*e.g.* `xmerl_xml:'#element#'`) can be specified for handling an element instead of the only option being to attempt to call a function matching the element name first and then calling the default element handler.

This commit also changes the `riak_cs_xml` module to pass in the tuples of `{'#element#', ElementName}` instead of just `ElementName` to directly use the default element callback function. This avoids having to implement a callback function for each and every element name and avoid the penalty of hitting the `code_server` numerous times when generating a response for a user request.

In my opinion `xmerl` is fundamentally flawed for not already having a way to directly specify a default element handler. I extracted the library and created a fork because even if we submit a patch to the OTP team to address this problem, it would still probably be 6 months or so before it made its way into a release and then more time before we would move to that new version of Erlang for Riak CS and even more time before we cut a release with it. I personally think having to add callbacks for each XML element name we might use is cumbersome and error prone. If we start using new element names and forget to add the appropriate callbacks then we silently take a performance hit. Using the fork I created we eliminate the overhead and the problem of silent performance degradation.