ocpsoft / prettytime

Social Style Date and Time Formatting for Java
http://ocpsoft.org/prettytime/
Apache License 2.0
1.29k stars 253 forks source link

Improve performance of SimpleTimeFormat #192

Closed theigl closed 4 years ago

theigl commented 4 years ago

String formatting in PrettyTime frequently shows up in my JFR profiler. It really should not, because it only performs basic string operations.

This PR applies two simple optimizations to SimpleTimeFormat:

The optimized version is nearly 4 times faster:

Benchmark Mode Cnt Score Units
Benchmarks.minutesAgoBaseline thrpt 6 790712,507 ops/s
Benchmarks.minutesAgoOptimized thrpt 6 3008068,573 ops/s
theigl commented 4 years ago

@lincolnthree: Please review.

lincolnthree commented 4 years ago

Hey @theigl apologies for the delay. Crazy around here with the launch of www.topdecked.com approaching. This looks great, will get it released ASAP.

theigl commented 4 years ago

Thanks @lincolnthree! And all the best for your launch!

lincolnthree commented 4 years ago

V 4.0.6.Final has been released to Sonatyle OSSRH staging/releases repo and should be available in Maven Central after tonight's nightly sync. Thanks so much for this performance enhancement!

I'm surprised nobody noticed this before, as it's a huge improvement/hotspot fix.

lincolnthree commented 4 years ago

Also thank you :) Not much sleep around here right now!