boxing + unboxing a VT is not a no-op ? (original) (raw)
Tobias Hartmann tobias.hartmann at oracle.com
Fri Jul 13 12:43:10 UTC 2018
- Previous message (by thread): boxing + unboxing a VT is not a no-op ?
- Next message (by thread): boxing + unboxing a VT is not a no-op ?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hi Remi,
thanks for reporting. Could you please provide the full source code so we can have a closer look?
Best regards, Tobias
On 12.07.2018 20:43, Remi Forax wrote:
Hi guys, it seems that operations likes VT -> Object -> VT are not optimized has being a no-op.
with IntBox being a value type that wrap an int, this code is slow (not very slow, i.e not interpreter slow) public int valuelistintboxinnervalueinlinedreduce() { _ByValue class Adder implements BiFunction<IntBox, IntBox, IntBox> { private final boolean nonEmpty; Adder() { nonEmpty = false; throw new AssertionError(); } public IntBox apply(IntBox acc, IntBox element) { return acc.add(element); } } _BiFunction<IntBox, IntBox, IntBox> mapper = MakeDefault Adder(); var sum = IntBox.zero(); int size = valueList.size(); for(int i = 0; i < size; i++) { sum = mapper.apply(sum, valueList.get(i)); } return sum.intValue(); } while this code is fast (more than 10 times faster) public int valuelistintboxinlinedreduce() { var sum = IntBox.zero(); int size = valueList.size(); for(int i = 0; i < size; i++) { sum = sum.add(valueList.get(i)); } return sum.intValue(); } the difference is that instead of calling add on an IntBox to do the addition, i used an anonymous value class which implement a functional interface which used Objects. (valueList is just an array of IntBox wrapped in a value type). regards, Rémi
- Previous message (by thread): boxing + unboxing a VT is not a no-op ?
- Next message (by thread): boxing + unboxing a VT is not a no-op ?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]