getkyo / kyo

Toolkit for Scala Development
https://getkyo.io
Apache License 2.0
527 stars 44 forks source link

tags: fix perf regression with int encoding #470

Closed fwbrasil closed 3 months ago

fwbrasil commented 3 months ago

I noticed a performance regression introduced by https://github.com/getkyo/kyo/pull/432. The mechanism to decode Ints has to scan an array of chars, which introduces overhead and even allocations in some cases because indexOf is an unoptimized Scala implementation.

This PR fixes the regression by moving the search to compile time and producing a table that can be used with a simple offset lookup.

Benchmark results:

image https://jmh.morethan.io/?sources=https://gist.githubusercontent.com/fwbrasil/872121366422a6cd4d1d19b9df1e95b9/raw/c4ccc79d42f61514c7fcdbdfc9ca12f4178caf67/jmh-result-baseline.json,https://gist.githubusercontent.com/fwbrasil/872121366422a6cd4d1d19b9df1e95b9/raw/c4ccc79d42f61514c7fcdbdfc9ca12f4178caf67/jmh-result-candidate.json