While looking at flame graphs for my application under the load, I found that my application was spending significant time on filling stack traces though there were no errors in logs.
I found that the reason is in that my application is heavily using Document#toJson method. Under the hood, the method creates a new instance of DocumentCodec. And deep inside there is also a call to create a new instance of BsonTypeCodecMap which has the following code:
try { codecs[cur.getValue()] = codecRegistry.get(clazz); } catch (CodecConfigurationException e) { // delay reporting this until the codec is actually requested }
The thing is in that it can't find a codec for BsonType "ARRAY" and clazz "interface java.util.List", then throws an exception, ignores it, and affects application performance.
I think that the simplest way to reproduce the issue is to set a breakpoint on the line with the catch condition and to create a new instance of DocumentCodec.