oh wow complete with custom CharSequence.parseInt(...
# advent-of-code
k
oh wow complete with custom CharSequence.parseInt(start)
j

https://i.kym-cdn.com/entries/icons/original/000/006/360/gottago.jpgâ–ľ

o
(nitpick) no check for int overflow 🙂
j
That would make it less fast =P
k
parseNode
isn't
inline
, boo!
You'd avoid the first call to
onMetadata
simple smile
j
@karelpeeters Large method body though…wouln’t it bloat code
k
Yeah you're probably right.
You can remove the
if (c in '0'..'9')
check too!
j
True! Lets live dangerously!
k
and maybe another nanosecond from assuming that the only kind of whitespace is
j
Shaved 0.09 ms. WORTH IT
Could probably save a few more by assuming theres no repeating whitespace also
k
And what do default parameters look like in bytecode again? Maybe they slow it down a bit too.
o
yes, if they some are ommitted, there is a bit check
j
True, I dont think I ever use the end arg of
CharSequence.indexOfFirst
k
You could also make
parseInt
check for whitespace, drop the
end
parameter and return the next index in the upper bits of the returned int.
j
Hmm ya, and return an inlined class instance to pull the value and next index out
I think could also be a bit faster by using
String
as input instead of
CharSequence
o
Yes, Strings are handled specially by JVM
j
Also should be
invokestatic
instead of
invokeinterface
as well
o
JIT will handle polymorphic with only one real class pretty good (after warmup)
k
Biggest performance difference would probably be to drop the
onMetaData
thing and just write the code straight.
j
And accumulate metadata sum in an argument?
k
Aren't there some more high bits left in the return of
parseNode
?
j
Haha
On second glance you’re right, in fact it HAS to be in the return because we dont know where the metadata are until after we parse children
@karelpeeters Set up JMH, tried with your suggested bit twiddles
Bit twiddling version was 1.04x function args vers
k
Huh that's interesting.
j
Very!
k
Would it be possible to quickly put my code though JMH as well? It runs in 0.5ms for me, but maybe that's just the pc?
j
@karelpeeters
Copy code
Day8Bench.day8part1joel   thrpt   25  6715.561 ± 84.500  ops/s
Day8Bench.day8part1karel  thrpt   25  1853.961 ±  5.016  ops/s
I removed the value calculation and prints to make it an even comparison
k
Cool, thanks for running it!
j
Sure thing
k
So you got a 10x improvement between this and the code you posted (that was 1.79ms)? Or is that mostly JMH measuring better?
j
better mesaurements