Replace BigDecimal#!= by BigDecimal#nonzero?. #4199

Merged
merged 1 commit into from Oct 3, 2016

Projects

None yet

2 participants

@felixvf
felixvf commented Oct 3, 2016

The comparison is very expensive, because it first tries to convert the operand (which is a constant Integer 0 here) into a BigDecimal. This in turn is very expensive (because the Integer is first converted into a String, and then, for operating on that String, a java.util.regex.Pattern object is compiled (in line https://github.com/felixvf/jruby/blob/cc79119315496ea019496affe7a6a79ebc1dbed9/core/src/main/java/org/jruby/ext/bigdecimal/RubyBigDecimal.java#L533)). Using #nonzero? should speed-up the loop considerably.

Felix von Ferey Replace BigDecimal#!= by BigDecimal#nonzero?.
The comparison is very expensive, because it first tries to convert the operand (which is a constant Integer 0 here) into a BigDecimal. This in turn is very expensive (because the Integer is first converted into a String, and then, for operating on that String, a java.util.regex.Pattern object is compiled (in line https://github.com/felixvf/jruby/blob/cc79119315496ea019496affe7a6a79ebc1dbed9/core/src/main/java/org/jruby/ext/bigdecimal/RubyBigDecimal.java#L533)). Using #nonzero? should speed-up the loop considerably.
3acd172
@kares kares added this to the JRuby 9.1.6.0 milestone Oct 3, 2016
@kares kares merged commit 8516d1f into jruby:master Oct 3, 2016

0 of 2 checks passed

continuous-integration/appveyor/pr AppVeyor build failed
Details
continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
@kares
Member
kares commented Oct 3, 2016

nice catch Felix, thanks

@felixvf felixvf deleted the felixvf:fix_bigmath_log_performance branch Oct 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment