Skip to content

Commit 6b50ebb

Browse files
authored
Improve the performance of Version.Component.parse (#2010)
1 parent 768cecb commit 6b50ebb

File tree

5 files changed

+49
-4
lines changed

5 files changed

+49
-4
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ jobs:
5959
uses: codecov/codecov-action@v1
6060

6161
- name: Compress target directories
62-
run: tar cf targets.tar target modules/core/.jvm/target modules/sbt-plugin/.jvm/target modules/mill-plugin/.jvm/target project/target
62+
run: tar cf targets.tar target modules/mill-plugin/.jvm/target modules/sbt-plugin/.jvm/target modules/core/.jvm/target modules/benchmark/.jvm/target project/target
6363

6464
- name: Upload target directories
6565
uses: actions/upload-artifact@v2

build.sbt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ val rootPkg = groupId.replace("-", "")
99
val gitHubOwner = "scala-steward-org"
1010

1111
val moduleCrossPlatformMatrix: Map[String, List[Platform]] = Map(
12+
"benchmark" -> List(JVMPlatform),
1213
"core" -> List(JVMPlatform),
1314
"sbt-plugin" -> List(JVMPlatform),
1415
"mill-plugin" -> List(JVMPlatform)
@@ -55,10 +56,19 @@ ThisBuild / githubWorkflowBuild :=
5556

5657
lazy val root = project
5758
.in(file("."))
58-
.aggregate(core.jvm, `sbt-plugin`.jvm, `mill-plugin`.jvm)
59+
.aggregate(benchmark.jvm, core.jvm, `sbt-plugin`.jvm, `mill-plugin`.jvm)
5960
.settings(commonSettings)
6061
.settings(noPublishSettings)
6162

63+
lazy val benchmark = myCrossProject("benchmark")
64+
.dependsOn(core)
65+
.enablePlugins(JmhPlugin)
66+
.settings(noPublishSettings)
67+
.settings(
68+
coverageEnabled := false,
69+
unusedCompileDependencies := Set.empty
70+
)
71+
6272
lazy val core = myCrossProject("core")
6373
.enablePlugins(BuildInfoPlugin, JavaAppPackaging, DockerPlugin)
6474
.settings(dockerSettings)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2018-2021 Scala Steward contributors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.scalasteward.benchmark
18+
19+
import org.openjdk.jmh.annotations.{Benchmark, BenchmarkMode, Mode, OutputTimeUnit}
20+
import org.scalasteward.core.data.Version
21+
22+
import java.util.concurrent.TimeUnit
23+
24+
@BenchmarkMode(Array(Mode.AverageTime))
25+
class VersionBenchmark {
26+
@Benchmark
27+
@OutputTimeUnit(TimeUnit.MICROSECONDS)
28+
def constructor: Any = {
29+
Version("1.1.2-1")
30+
Version("8.0.192-R14")
31+
Version("1.2.0+9-4a769501")
32+
}
33+
}

modules/core/src/main/scala/org/scalasteward/core/data/Version.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,13 @@ object Version {
156156

157157
def parse(str: String): List[Component] =
158158
str match {
159-
case hash(sep, value, rest) if !startsWithDate(value) =>
160-
Separator(sep.head) +: Hash(value) +: parse(rest)
159+
case "" => List.empty
161160
case numeric(value, rest) =>
162161
Numeric(value) +: parse(rest)
163162
case alpha(value, rest) =>
164163
Alpha(value) +: parse(rest)
164+
case hash(sep, value, rest) if !startsWithDate(value) =>
165+
Separator(sep.head) +: Hash(value) +: parse(rest)
165166
case separator(value, rest) =>
166167
Separator(value.head) +: parse(rest)
167168
case _ => List.empty

project/plugins.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ addSbtPlugin("com.github.tkawachi" % "sbt-doctest" % "0.9.9")
88
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.8.1")
99
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.6.0")
1010
addSbtPlugin("io.github.davidgregory084" % "sbt-tpolecat" % "0.1.17")
11+
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.0")
1112
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.0.0")
1213
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.1")
1314
addSbtPlugin("org.wartremover" % "sbt-wartremover" % "2.4.13")

0 commit comments

Comments
 (0)