Skip to content

Commit 35f9d91

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/master' into config-utils
2 parents 00c88ac + bed0a13 commit 35f9d91

File tree

24 files changed

+629
-118
lines changed

24 files changed

+629
-118
lines changed

.github/workflows/ci.yml

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,34 @@ jobs:
2424
strategy:
2525
matrix:
2626
os: [ubuntu-latest]
27-
scala: [2.13.13]
28-
java: [temurin@11, temurin@17]
27+
scala: [2.13.14]
28+
java: [temurin@17, temurin@21]
2929
runs-on: ${{ matrix.os }}
3030
steps:
3131
- name: Checkout current branch (full)
3232
uses: actions/checkout@v4
3333
with:
3434
fetch-depth: 0
3535

36-
- name: Setup Java (temurin@11)
37-
if: matrix.java == 'temurin@11'
36+
- name: Setup Java (temurin@17)
37+
if: matrix.java == 'temurin@17'
3838
uses: actions/setup-java@v4
3939
with:
4040
distribution: temurin
41-
java-version: 11
41+
java-version: 17
4242
cache: sbt
4343

44-
- name: Setup Java (temurin@17)
45-
if: matrix.java == 'temurin@17'
44+
- name: Setup Java (temurin@21)
45+
if: matrix.java == 'temurin@21'
4646
uses: actions/setup-java@v4
4747
with:
4848
distribution: temurin
49-
java-version: 17
49+
java-version: 21
5050
cache: sbt
5151

52+
- name: Setup sbt
53+
uses: sbt/setup-sbt@v1
54+
5255
- name: Cache Redis
5356
uses: actions/cache@v2
5457
with:
@@ -61,9 +64,9 @@ jobs:
6164
node-version: 12
6265

6366
- name: Setup MongoDB
64-
uses: supercharge/mongodb-github-action@1.9.0
67+
uses: supercharge/mongodb-github-action@1.10.0
6568
with:
66-
mongodb-version: 6.0
69+
mongodb-version: 7.0
6770
mongodb-replica-set: test-rs
6871

6972
- name: Setup Redis
@@ -82,31 +85,34 @@ jobs:
8285
strategy:
8386
matrix:
8487
os: [ubuntu-latest]
85-
scala: [2.13.13]
86-
java: [temurin@11]
88+
scala: [2.13.14]
89+
java: [temurin@17]
8790
runs-on: ${{ matrix.os }}
8891
steps:
8992
- name: Checkout current branch (full)
9093
uses: actions/checkout@v4
9194
with:
9295
fetch-depth: 0
9396

94-
- name: Setup Java (temurin@11)
95-
if: matrix.java == 'temurin@11'
97+
- name: Setup Java (temurin@17)
98+
if: matrix.java == 'temurin@17'
9699
uses: actions/setup-java@v4
97100
with:
98101
distribution: temurin
99-
java-version: 11
102+
java-version: 17
100103
cache: sbt
101104

102-
- name: Setup Java (temurin@17)
103-
if: matrix.java == 'temurin@17'
105+
- name: Setup Java (temurin@21)
106+
if: matrix.java == 'temurin@21'
104107
uses: actions/setup-java@v4
105108
with:
106109
distribution: temurin
107-
java-version: 17
110+
java-version: 21
108111
cache: sbt
109112

113+
- name: Setup sbt
114+
uses: sbt/setup-sbt@v1
115+
110116
- env:
111117
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
112118
PGP_SECRET: ${{ secrets.PGP_SECRET }}

benchmark/js/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
How to run benchmark:
2+
- compile `sbt commons-benchmark-js/fullOptJS`
3+
- open `fullopt-2.13.html` file in a browser
4+
- select test suite and run

benchmark/js/src/main/scala/com/avsystem/commons/ser/JsonBenchmarks.scala

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.avsystem.commons
22
package ser
33

44
import com.avsystem.commons.serialization.json.{JsonStringInput, JsonStringOutput}
5+
import com.avsystem.commons.serialization.nativejs.{NativeJsonInput, NativeJsonOutput}
56
import io.circe.parser._
67
import io.circe.syntax._
78
import japgolly.scalajs.benchmark.gui.GuiSuite
@@ -10,62 +11,86 @@ import japgolly.scalajs.benchmark.{Benchmark, Suite}
1011
object JsonBenchmarks {
1112
val suite = GuiSuite(
1213
Suite("JSON serialization benchmarks")(
13-
Benchmark("Writing case class: GenCodec") {
14+
Benchmark("Writing case class: GenCodec, String Json format") {
1415
JsonStringOutput.write(Something.Example)
1516
},
17+
Benchmark("Writing case class: GenCodec, Native Json format") {
18+
NativeJsonOutput.writeAsString(Something.Example)
19+
},
1620
Benchmark("Writing case class: Circe") {
1721
Something.Example.asJson.noSpaces
1822
},
1923
Benchmark("Writing case class: uPickle") {
2024
upickle.default.write(Something.Example)
2125
},
22-
Benchmark("Reading case class: GenCodec") {
26+
Benchmark("Reading case class: GenCodec, String Json format") {
2327
JsonStringInput.read[Something](Something.ExampleJsonString)
2428
},
29+
Benchmark("Reading case class: GenCodec, Native Json format") {
30+
NativeJsonInput.readString[Something](Something.ExampleJsonString)
31+
},
2532
Benchmark("Reading case class: Circe") {
2633
decode[Something](Something.ExampleJsonString).fold(e => throw e, identity)
2734
},
2835
Benchmark("Reading case class: uPickle") {
2936
upickle.default.read[Something](Something.ExampleJsonString)
3037
},
3138

32-
Benchmark("Writing sealed hierarchy: GenCodec") {
39+
Benchmark("Writing sealed hierarchy: GenCodec, String Json format") {
3340
JsonStringOutput.write(SealedStuff.ExampleList)
3441
},
35-
Benchmark("Writing sealed hierarchy: GenCodec (flat)") {
42+
Benchmark("Writing sealed hierarchy: GenCodec (flat), String Json format") {
3643
JsonStringOutput.write(FlatSealedStuff.ExampleList)
3744
},
45+
Benchmark("Writing sealed hierarchy: GenCodec, Native Json format") {
46+
NativeJsonOutput.writeAsString(SealedStuff.ExampleList)
47+
},
48+
Benchmark("Writing sealed hierarchy: GenCodec (flat), Native Json format") {
49+
NativeJsonOutput.writeAsString(FlatSealedStuff.ExampleList)
50+
},
3851
Benchmark("Writing sealed hierarchy: Circe") {
3952
SealedStuff.ExampleList.asJson.noSpaces
4053
},
4154
Benchmark("Writing sealed hierarchy: uPickle") {
4255
upickle.default.write(SealedStuff.ExampleList)
4356
},
44-
Benchmark("Reading sealed hierarchy: GenCodec") {
57+
Benchmark("Reading sealed hierarchy: GenCodec, String Json format") {
4558
JsonStringInput.read[List[SealedStuff]](SealedStuff.ExampleJsonString)
4659
},
47-
Benchmark("Reading sealed hierarchy: GenCodec (flat)") {
60+
Benchmark("Reading sealed hierarchy: GenCodec (flat), String Json format") {
4861
JsonStringInput.read[List[FlatSealedStuff]](FlatSealedStuff.ExampleJsonString)
4962
},
63+
Benchmark("Reading sealed hierarchy: GenCodec, Native Json format") {
64+
NativeJsonInput.readString[List[SealedStuff]](SealedStuff.ExampleJsonString)
65+
},
66+
Benchmark("Reading sealed hierarchy: GenCodec (flat), Native Json format") {
67+
NativeJsonInput.readString[List[FlatSealedStuff]](FlatSealedStuff.ExampleJsonString)
68+
},
5069
Benchmark("Reading sealed hierarchy: Circe") {
5170
decode[List[SealedStuff]](SealedStuff.ExampleJsonString).fold(e => throw e, identity)
5271
},
5372
Benchmark("Reading sealed hierarchy: uPickle") {
5473
upickle.default.read[List[SealedStuff]](SealedStuff.ExampleUpickleJsonString)
5574
},
5675

57-
Benchmark("Writing foos: GenCodec") {
76+
Benchmark("Writing foos: GenCodec, String Json format") {
5877
JsonStringOutput.write(Foo.ExampleMap)
5978
},
79+
Benchmark("Writing foos: GenCodec, Native Json format") {
80+
NativeJsonOutput.writeAsString(Foo.ExampleMap)
81+
},
6082
Benchmark("Writing foos: Circe") {
6183
Foo.ExampleMap.asJson.noSpaces
6284
},
6385
Benchmark("Writing foos: uPickle") {
6486
upickle.default.write(Foo.ExampleMap)
6587
},
66-
Benchmark("Reading foos: GenCodec") {
88+
Benchmark("Reading foos: GenCodec, String Json format") {
6789
JsonStringInput.read[Map[String, Foo]](Foo.ExampleJsonString)
6890
},
91+
Benchmark("Reading foos: GenCodec with Native Json format") {
92+
NativeJsonInput.readString[Map[String, Foo]](Foo.ExampleJsonString)
93+
},
6994
Benchmark("Reading foos: Circe") {
7095
decode[Map[String, Foo]](Foo.ExampleJsonString).fold(e => throw e, identity)
7196
},
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.avsystem.commons
2+
package serialization.nativejs
3+
4+
import com.avsystem.commons.misc.{AbstractValueEnum, AbstractValueEnumCompanion, EnumCtx}
5+
6+
/**
7+
* Specifies format used by `NativeJsonOutput.writeLong` / `NativeJsonInput.readLong`
8+
* to represent [[Long]]. JS does not support 64-bit representation.
9+
*/
10+
final class NativeLongFormat(implicit ctx: EnumCtx) extends AbstractValueEnum
11+
object NativeLongFormat extends AbstractValueEnumCompanion[NativeLongFormat] {
12+
final val RawString: Value = new NativeLongFormat
13+
final val JsNumber: Value = new NativeLongFormat
14+
final val JsBigInt: Value = new NativeLongFormat
15+
}
16+
17+
/**
18+
* Specifies format used by `NativeJsonOutput.writeTimestamp` / `NativeJsonInput.readTimestamp`
19+
* to represent timestamps.
20+
*/
21+
final class NativeDateFormat(implicit ctx: EnumCtx) extends AbstractValueEnum
22+
object NativeDateFormat extends AbstractValueEnumCompanion[NativeDateFormat] {
23+
final val RawString: Value = new NativeDateFormat
24+
final val JsNumber: Value = new NativeDateFormat
25+
final val JsDate: Value = new NativeDateFormat
26+
}
27+
28+
/**
29+
* Specifies format used by `NativeJsonOutput.writeBigInt` / `NativeJsonInput.readBigInt`
30+
* to represent [[BigInt]].
31+
*
32+
* Note that [[scala.scalajs.js.JSON.stringify]] does not know how to serialize a BigInt and throws an error
33+
*/
34+
final class NativeBigIntFormat(implicit ctx: EnumCtx) extends AbstractValueEnum
35+
object NativeBigIntFormat extends AbstractValueEnumCompanion[NativeBigIntFormat] {
36+
final val RawString: Value = new NativeBigIntFormat
37+
final val JsBigInt: Value = new NativeBigIntFormat
38+
}
39+
40+
/**
41+
* Adjusts format produced by [[NativeJsonOutput]].
42+
*
43+
* @param longFormat format used to [[Long]]
44+
* @param dateFormat format used to represent timestamps
45+
* @param bigIntFormat format used to represent [[BigInt]]
46+
*/
47+
final case class NativeFormatOptions(
48+
longFormat: NativeLongFormat = NativeLongFormat.RawString,
49+
dateFormat: NativeDateFormat = NativeDateFormat.RawString,
50+
bigIntFormat: NativeBigIntFormat = NativeBigIntFormat.RawString,
51+
)
52+
object NativeFormatOptions {
53+
final val RawString = NativeFormatOptions()
54+
}

0 commit comments

Comments
 (0)