Skip to content

Conversation

@aldexis
Copy link
Contributor

@aldexis aldexis commented Aug 25, 2025

Before this PR

When parsing an orderable sls version, we're doing up to 4 parsing of the same string (one for each version type), which is fairly inefficient and leads to extra code as well.

We've also implemented a dedicated, more optimized version parser for release versions in #463, which can be easily extended to the other version types, but for these we're still relying on the basic regex parsing.

After this PR

==COMMIT_MSG==
Streamline orderable sls version parsing
==COMMIT_MSG==

Performance comparison shows high improvements on both speed and memory allocations for non-release version parsing. Specifically surfacing these:

Version type Speed before (ns/op) Speed after (ns/op) Allocations before (B/op) Allocations after (B/op)
RC 139 36 352 104
SNAPSHOT 270 61 808 104
RC_SNAPSHOT 235 50 584 56

See complete JMH results below:
Before (as of #1183)

Benchmark                                           (versionString)  Mode  Cnt      Score      Error   Units
SlsVersionBenchmark.safeValueOf                             RELEASE  avgt    3     16.798 ±    0.887   ns/op
SlsVersionBenchmark.safeValueOf:gc.alloc.rate               RELEASE  avgt    3  12715.520 ±  667.856  MB/sec
SlsVersionBenchmark.safeValueOf:gc.alloc.rate.norm          RELEASE  avgt    3     56.000 ±    0.001    B/op
SlsVersionBenchmark.safeValueOf:gc.count                    RELEASE  avgt    3    189.000             counts
SlsVersionBenchmark.safeValueOf:gc.time                     RELEASE  avgt    3    100.000                 ms
SlsVersionBenchmark.safeValueOf                            SNAPSHOT  avgt    3    270.576 ±   22.299   ns/op
SlsVersionBenchmark.safeValueOf:gc.alloc.rate              SNAPSHOT  avgt    3  11390.574 ±  935.650  MB/sec
SlsVersionBenchmark.safeValueOf:gc.alloc.rate.norm         SNAPSHOT  avgt    3    808.000 ±    0.001    B/op
SlsVersionBenchmark.safeValueOf:gc.count                   SNAPSHOT  avgt    3    194.000             counts
SlsVersionBenchmark.safeValueOf:gc.time                    SNAPSHOT  avgt    3    101.000                 ms
SlsVersionBenchmark.safeValueOf                                  RC  avgt    3    139.038 ±    3.726   ns/op
SlsVersionBenchmark.safeValueOf:gc.alloc.rate                    RC  avgt    3   9656.714 ±  257.133  MB/sec
SlsVersionBenchmark.safeValueOf:gc.alloc.rate.norm               RC  avgt    3    352.000 ±    0.001    B/op
SlsVersionBenchmark.safeValueOf:gc.count                         RC  avgt    3    194.000             counts
SlsVersionBenchmark.safeValueOf:gc.time                          RC  avgt    3     97.000                 ms
SlsVersionBenchmark.safeValueOf                         RC_SNAPSHOT  avgt    3    235.163 ±   38.654   ns/op
SlsVersionBenchmark.safeValueOf:gc.alloc.rate           RC_SNAPSHOT  avgt    3   9472.974 ± 1551.075  MB/sec
SlsVersionBenchmark.safeValueOf:gc.alloc.rate.norm      RC_SNAPSHOT  avgt    3    584.000 ±    0.001    B/op
SlsVersionBenchmark.safeValueOf:gc.count                RC_SNAPSHOT  avgt    3    161.000             counts
SlsVersionBenchmark.safeValueOf:gc.time                 RC_SNAPSHOT  avgt    3     86.000                 ms
SlsVersionBenchmark.safeValueOf                               DIRTY  avgt    3    247.986 ±   12.286   ns/op
SlsVersionBenchmark.safeValueOf:gc.alloc.rate                 DIRTY  avgt    3  10459.128 ±  520.746  MB/sec
SlsVersionBenchmark.safeValueOf:gc.alloc.rate.norm            DIRTY  avgt    3    680.000 ±    0.001    B/op
SlsVersionBenchmark.safeValueOf:gc.count                      DIRTY  avgt    3    215.000             counts
SlsVersionBenchmark.safeValueOf:gc.time                       DIRTY  avgt    3    110.000                 ms
SlsVersionBenchmark.safeValueOf                            DIRTY_RC  avgt    3    242.851 ±    1.067   ns/op
SlsVersionBenchmark.safeValueOf:gc.alloc.rate              DIRTY_RC  avgt    3  10680.313 ±   47.130  MB/sec
SlsVersionBenchmark.safeValueOf:gc.alloc.rate.norm         DIRTY_RC  avgt    3    680.000 ±    0.001    B/op
SlsVersionBenchmark.safeValueOf:gc.count                   DIRTY_RC  avgt    3    198.000             counts
SlsVersionBenchmark.safeValueOf:gc.time                    DIRTY_RC  avgt    3    101.000                 ms

After

Benchmark                                           (versionString)  Mode  Cnt      Score      Error   Units
SlsVersionBenchmark.safeValueOf                             RELEASE  avgt    3     16.600 ±    0.271   ns/op
SlsVersionBenchmark.safeValueOf:gc.alloc.rate               RELEASE  avgt    3  12867.557 ±  211.704  MB/sec
SlsVersionBenchmark.safeValueOf:gc.alloc.rate.norm          RELEASE  avgt    3     56.000 ±    0.001    B/op
SlsVersionBenchmark.safeValueOf:gc.count                    RELEASE  avgt    3    215.000             counts
SlsVersionBenchmark.safeValueOf:gc.time                     RELEASE  avgt    3    111.000                 ms
SlsVersionBenchmark.safeValueOf                            SNAPSHOT  avgt    3     61.063 ±    3.971   ns/op
SlsVersionBenchmark.safeValueOf:gc.alloc.rate              SNAPSHOT  avgt    3   6496.363 ±  423.071  MB/sec
SlsVersionBenchmark.safeValueOf:gc.alloc.rate.norm         SNAPSHOT  avgt    3    104.000 ±    0.001    B/op
SlsVersionBenchmark.safeValueOf:gc.count                   SNAPSHOT  avgt    3    159.000             counts
SlsVersionBenchmark.safeValueOf:gc.time                    SNAPSHOT  avgt    3     77.000                 ms
SlsVersionBenchmark.safeValueOf                                  RC  avgt    3     36.197 ±   12.191   ns/op
SlsVersionBenchmark.safeValueOf:gc.alloc.rate                    RC  avgt    3  10961.551 ± 3680.314  MB/sec
SlsVersionBenchmark.safeValueOf:gc.alloc.rate.norm               RC  avgt    3    104.000 ±    0.001    B/op
SlsVersionBenchmark.safeValueOf:gc.count                         RC  avgt    3    193.000             counts
SlsVersionBenchmark.safeValueOf:gc.time                          RC  avgt    3    101.000                 ms
SlsVersionBenchmark.safeValueOf                         RC_SNAPSHOT  avgt    3     50.665 ±    3.778   ns/op
SlsVersionBenchmark.safeValueOf:gc.alloc.rate           RC_SNAPSHOT  avgt    3   4215.982 ±  314.858  MB/sec
SlsVersionBenchmark.safeValueOf:gc.alloc.rate.norm      RC_SNAPSHOT  avgt    3     56.000 ±    0.001    B/op
SlsVersionBenchmark.safeValueOf:gc.count                RC_SNAPSHOT  avgt    3    128.000             counts
SlsVersionBenchmark.safeValueOf:gc.time                 RC_SNAPSHOT  avgt    3     58.000                 ms
SlsVersionBenchmark.safeValueOf                               DIRTY  avgt    3     37.939 ±    0.934   ns/op
SlsVersionBenchmark.safeValueOf:gc.alloc.rate                 DIRTY  avgt    3      0.003 ±    0.001  MB/sec
SlsVersionBenchmark.safeValueOf:gc.alloc.rate.norm            DIRTY  avgt    3     ≈ 10⁻⁵               B/op
SlsVersionBenchmark.safeValueOf:gc.count                      DIRTY  avgt    3        ≈ 0             counts
SlsVersionBenchmark.safeValueOf                            DIRTY_RC  avgt    3     46.842 ±    8.611   ns/op
SlsVersionBenchmark.safeValueOf:gc.alloc.rate              DIRTY_RC  avgt    3      0.003 ±    0.001  MB/sec
SlsVersionBenchmark.safeValueOf:gc.alloc.rate.norm         DIRTY_RC  avgt    3     ≈ 10⁻⁴               B/op
SlsVersionBenchmark.safeValueOf:gc.count                   DIRTY_RC  avgt    3        ≈ 0             counts

This PR also removes a few now-unnecessary package-private classes

Possible downsides?

return getValue();
}

private static int groupAsInt(String value, Matcher matcher, int group) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extracted out from RegexMatchResult, since it felt unnecessary to have the entire class + the parsers just for this (especially since NonOrderableSlsVersion is the less common usecase).

I'll move this to a separate util class though

import com.palantir.logsafe.Preconditions;
import javax.annotation.Nullable;

enum OrderableSlsVersionParser {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should add some javadoc here (even though it was missing from ReleaseVersionParser)

@aldexis aldexis force-pushed the ald/better-sls-version-comparison branch from 5067776 to 43cc394 Compare August 25, 2025 13:41
@aldexis
Copy link
Contributor Author

aldexis commented Aug 29, 2025

While this might indeed improve performance, there is no indication so far that this is needed anywhere. As such, I'll close this PR

@aldexis aldexis closed this Aug 29, 2025
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.

2 participants