-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Opt performance enhancement #334
Comments
the try/catch would need to stay in case of exceptions we don't actually plan on. But a pull request to enhance the opt* functions to be more performant would be welcome. Test cases should also be updated if needed in the separate test case project. |
Sure, you can propose a pull request if you have a code change in mind. Please see the FAQ more guidance on submitting code changes (https://github.com/stleary/JSON-java/wiki/FAQ). For performance enhancements, it will be helpful if you can provide some timing results to quantify the change. |
I am checking if I can contribute to the project. Until then, here is an example of code that can do it. It is published in open source under EPL so what you do with it is up to you. ;) |
Hi all, that's a good catch, generally speaking relaying on exceptions for normal code flow is most likely to be slower than doing some checks like in this case if the value is absent. Throwing exceptions will render stack traces and other things involved which will usually make the code slower by a factor, this can be easily proven, though might be unnecessary as it is a well known fact. There are many articles about this but this is one example: http://stackoverflow.com/questions/1546514/java-exceptions-as-control-flow |
@guidomedina please don't spam |
This issue has been superseded by pull request #337, please post future comments there. |
Hi, I am currently using your lib to parse json logs that can be very large. I was wondering if it would be possible to make opts have an early failure. The reason I am asking is while
try{
return getThing(string);
}catch(exception e){
return defaultValue;
}
is super readable, the throw catch exception is very slow. It would speed things up a lot having a simple check in front of the field to return if there is no field defined from the get go.
Thanks for such a great and easy to use lib.
:)
The text was updated successfully, but these errors were encountered: