Details
-
Improvement
-
Status: Resolved
-
Resolution: Done
-
None
-
None
-
None
-
None
-
Operating System: All
Platform: All
Description
Profiling cbench I have encountered performance overhead when constructing FlowCookie class – 20528ms for 105187 invocations. Of that, 15894ms was spent in Range.closed() invocations.
Looking at the generated code:
public FlowCookie(BigInteger _value) {
if (_value != null) {
boolean isValidRange = false;
List<Range<BigInteger>> rangeConstraints = new ArrayList<>();
rangeConstraints.add(Range.closed(new BigInteger("0"), new BigInteger("18446744073709551615")));
for (Range<BigInteger> r : rangeConstraints) {
if (r.contains(_value))
}
if (!isValidRange)
}
this._value = _value;
}
It is rather obvious we can do better:
1) those range constraints should be lazily generated, but retained as static fields (double-checked loading)
2) BigInteger("0") should be replaced with BigInteger.ZERO (also ONE and TEN)
3) For values less that Long.MAX_VALUE, we should use BigInteger.valueOf(long)
4) rangeConstraints should end up being an ImmutableList
Attachments
Issue Links
- is duplicated by
-
YANGTOOLS-186 Odd use of number constructors in generated code
- Resolved