ReactiveMongo/ReactiveMongo — pull request #226 by MrBagheera (2014-12-10 11:11:27+00:00)
Title: more efficient parsing of optional parameters (avoid unneeded throws)

Hi!

Our project uses data structures with a lot of optional fields (in form of Option[A]). When profiling it under load, I've noticed that JVM spends unusually high amount of CPU time (10-20%) in `Throwable.fillInStackTrace`.

![proof](https://cloud.githubusercontent.com/assets/954015/5374956/956ad9b6-806d-11e4-864e-0c6e7181b41b.PNG)

Further investigation showed that this is mostly called from `BSONDocument.getAsTry` from inside macro-generated parsers. While original reasoning behind this approach (*make macros-generated reader to throw meaningful exceptions instead of java.util.NoSuchElementException: None.get*) is solid, I believe in case of optional fields using `getAsTry...toOption` is unnecessary and only hurts performance.

This fix changes parsing for optional fields back to simple `getAs`, while still keeping `getAsTry...get` path for non-optional fields.