SimpleJwkFilter throws excessive amount of ClassCastException
The getCrv and getThumbs methods in SimpleJwkFilter uses ClassCastException as a control-flow mechanism, which impacts performance (even though there is no semantic fault here).
This overhead could easily be mitigated by instead checking instanceof of the object before performing the casting, and simply return EMPTY if that condition evaluates false.
Comments (5)
-
repo owner -
reporter Exceptions are typically very costly and we see this in our JMC JFR profilings (otherwise I would not have found it).
I tried to reproduce in JMH benchmark but in that the JIT is able to optimize the try/catch completely through inlining, but this does not seem to happen in our production.
Besides, doesn’t the code look nicer than having a try/catch?
String getCrv() { if (!(jwk instanceof EllipticCurveJsonWebKey)) { return null; } return ((EllipticCurveJsonWebKey) jwk).getCurveName(); }
-
repo owner - marked as minor
will consider making the change(s)
-
repo owner - changed status to resolved
-
repo owner - changed status to closed
released in jose4j-0.7.0 https://bitbucket.org/b_c/jose4j/wiki/Release%20Notes#!jose4j-070-january-17-2019
- Log in to comment
Same or similar to https://bitbucket.org/b_c/jose4j/issues/137/extra-stack-generated-by
Are you seeing measurable performance issues or symptoms?