GeoLatte / geolatte-geom

A geometry model that conforms to the OGC Simple Features for SQL specification.
Other
132 stars 63 forks source link

Performance improvements in ByteBuffer.from() #79

Closed nbraun closed 4 years ago

nbraun commented 4 years ago

During a profiling session using Hibernate and Postgres, ByteBuffer.from(hexString) popped at the top of the slow functions.

After looking at the function, it appeared, that splitting the string is quite time and memory intense.

This patch implements a conversion from characters using only integer math, some bit shifting and so on. It tries to be as much compliant to the Integer.parse(string, radix) function, as used prior in order to keep the behaviour of the API stable. Therefore also some extra unit tests.

Tests with a 10k long string in a loop of 100k times showed that it could be converted in around 2.4s whereas the original implementation took around 20s.

maesenka commented 4 years ago

Thank you for this contribution!