You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by GitBox <gi...@apache.org> on 2023/01/09 22:30:21 UTC
[GitHub] [commons-lang] fenik17 opened a new pull request, #1015: Explicitly checks string for emptiness to prevent the exception logic overhead
fenik17 opened a new pull request, #1015:
URL: https://github.com/apache/commons-lang/pull/1015
Adding the fail fast checks for empty string into `NumberUtils` methods (like `toInt`, `toLong`, etc.) to prevent a big overhead due to generating exception.
Checking for an empty string is cheap, and a case with an empty string is quite likely.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-lang] garydgregory commented on pull request #1015: Explicitly checks string for emptiness to prevent the exception logic overhead
Posted by GitBox <gi...@apache.org>.
garydgregory commented on PR #1015:
URL: https://github.com/apache/commons-lang/pull/1015#issuecomment-1376552601
How much is the overhead and how did you measure it?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-lang] garydgregory commented on pull request #1015: Explicitly checks string for emptiness to prevent the exception logic overhead
Posted by GitBox <gi...@apache.org>.
garydgregory commented on PR #1015:
URL: https://github.com/apache/commons-lang/pull/1015#issuecomment-1377155679
That's not what your benchmark shows...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-lang] garydgregory commented on pull request #1015: Explicitly checks string for emptiness to prevent the exception logic overhead
Posted by GitBox <gi...@apache.org>.
garydgregory commented on PR #1015:
URL: https://github.com/apache/commons-lang/pull/1015#issuecomment-1377074910
So... there is one case out of three where the PR helps and the others two make things possibly worse due to the error margins?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-lang] fenik17 commented on pull request #1015: Explicitly checks string for emptiness to prevent the exception logic overhead
Posted by GitBox <gi...@apache.org>.
fenik17 commented on PR #1015:
URL: https://github.com/apache/commons-lang/pull/1015#issuecomment-1377189593
@garydgregory could you explain, please? I see the difference is within the margin of error:
```
Benchmark Mode Cnt Score Error Units
ToIntBenchmark.toIntNew_number avgt 5 1,682 ± 0,021 ns/op
ToIntBenchmark.toIntOld_number avgt 5 1,683 ± 0,012 ns/op
```
I understand that additional check can worth some CPU time. But in this case, it's literally fractions of nanoseconds. And this is incommensurable with the possible profit.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-lang] codecov-commenter commented on pull request #1015: Explicitly checks string for emptiness to prevent the exception logic overhead
Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on PR #1015:
URL: https://github.com/apache/commons-lang/pull/1015#issuecomment-1376819707
# [Codecov](https://codecov.io/gh/apache/commons-lang/pull/1015?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
> Merging [#1015](https://codecov.io/gh/apache/commons-lang/pull/1015?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (76587b3) into [master](https://codecov.io/gh/apache/commons-lang/commit/ac2062d939db4472a987cc4e7b38c78bd4b5f010?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (ac2062d) will **not change** coverage.
> The diff coverage is `100.00%`.
```diff
@@ Coverage Diff @@
## master #1015 +/- ##
=========================================
Coverage 92.03% 92.03%
Complexity 7429 7429
=========================================
Files 193 193
Lines 15672 15672
Branches 2899 2899
=========================================
Hits 14423 14423
Misses 676 676
Partials 573 573
```
| [Impacted Files](https://codecov.io/gh/apache/commons-lang/pull/1015?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
|---|---|---|
| [...ava/org/apache/commons/lang3/math/NumberUtils.java](https://codecov.io/gh/apache/commons-lang/pull/1015?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2NvbW1vbnMvbGFuZzMvbWF0aC9OdW1iZXJVdGlscy5qYXZh) | `95.02% <100.00%> (ø)` | |
:mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-lang] fenik17 commented on pull request #1015: Explicitly checks string for emptiness to prevent the exception logic overhead
Posted by GitBox <gi...@apache.org>.
fenik17 commented on PR #1015:
URL: https://github.com/apache/commons-lang/pull/1015#issuecomment-1377054540
@garydgregory it is minimum 1000 times difference. [Benchmark here](https://github.com/fenik17/commons-lang/blob/to_int_benchmark/src/test/java/org/apache/commons/lang3/ToIntBenchmark.java).
Results on my laptop:
```
Benchmark Mode Cnt Score Error Units
ToIntBenchmark.toIntNew_emptyString avgt 5 0,382 ± 0,016 ns/op
ToIntBenchmark.toIntNew_notNumber avgt 5 1449,161 ± 17,574 ns/op
ToIntBenchmark.toIntNew_number avgt 5 1,682 ± 0,021 ns/op
ToIntBenchmark.toIntOld_emptyString avgt 5 1456,267 ± 19,870 ns/op
ToIntBenchmark.toIntOld_notNumber avgt 5 1443,685 ± 15,124 ns/op
ToIntBenchmark.toIntOld_number avgt 5 1,683 ± 0,012 ns/op
```
Exceptions are [very expensive](https://www.baeldung.com/java-exceptions-performance).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-lang] fenik17 commented on pull request #1015: Explicitly checks string for emptiness to prevent the exception logic overhead
Posted by GitBox <gi...@apache.org>.
fenik17 commented on PR #1015:
URL: https://github.com/apache/commons-lang/pull/1015#issuecomment-1377151202
@garydgregory if an empty string is coming (it is often case in my practice), this change can drastically improve performance. In other cases degradation is not noticeable.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Explicitly checks string for emptiness to prevent the exception logic overhead [commons-lang]
Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on PR #1015:
URL: https://github.com/apache/commons-lang/pull/1015#issuecomment-2299254403
Closing: Edge case not worth the clutter. Code is simpler in master now anyway, no need to check for null since the catch will handle it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Explicitly checks string for emptiness to prevent the exception logic overhead [commons-lang]
Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory closed pull request #1015: Explicitly checks string for emptiness to prevent the exception logic overhead
URL: https://github.com/apache/commons-lang/pull/1015
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org