Skip to content

Simplify ShadowColor#fromHexString implementation - #1453

Open
SirYwell wants to merge 2 commits into
PaperMC:main/5from
SirYwell:perf/shadowcolor-fromhex
Open

SirYwell wants to merge 2 commits into
PaperMC:main/5from
SirYwell:perf/shadowcolor-fromhex

Conversation

@SirYwell

Copy link
Copy Markdown

Instead of creating four substrings and parse them separately, we can just parse one unsigned integer and rotate the result to put the different channels at the right position. In fact, we can completely avoid string copying by using the parse method that also takes start/end offsets.

The microbenchmark also shows improvements:

Benchmark (before)                                     (hexString)    Mode     Cnt     Score     Error   Units
ShadowColorBenchmark.fromHexString                       #AABBCCDD  sample  235566     0.061 ±   0.011   us/op
ShadowColorBenchmark.fromHexString:gc.alloc.rate         #AABBCCDD  sample       3  2859.931 ± 299.860  MB/sec
ShadowColorBenchmark.fromHexString:gc.alloc.rate.norm    #AABBCCDD  sample       3   112.002 ±   0.010    B/op
ShadowColorBenchmark.fromHexString                       #12345678  sample  224510     0.059 ±   0.001   us/op
ShadowColorBenchmark.fromHexString:gc.alloc.rate         #12345678  sample       3  2725.432 ± 639.234  MB/sec
ShadowColorBenchmark.fromHexString:gc.alloc.rate.norm    #12345678  sample       3   112.002 ±   0.001    B/op
Benchmark (after)                                      (hexString)    Mode     Cnt     Score     Error   Units
ShadowColorBenchmark.fromHexString                       #AABBCCDD  sample  284336    0.035 ±   0.001   us/op
ShadowColorBenchmark.fromHexString:gc.alloc.rate         #AABBCCDD  sample       3  986.690 ± 120.980  MB/sec
ShadowColorBenchmark.fromHexString:gc.alloc.rate.norm    #AABBCCDD  sample       3   16.001 ±   0.003    B/op
ShadowColorBenchmark.fromHexString                       #12345678  sample  283923    0.035 ±   0.001   us/op
ShadowColorBenchmark.fromHexString:gc.alloc.rate         #12345678  sample       3  985.166 ±  55.692  MB/sec
ShadowColorBenchmark.fromHexString:gc.alloc.rate.norm    #12345678  sample       3   16.001 ±   0.003    B/op

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant