[Scala] support scala collection jit serialization#1077
Merged
chaokunyang merged 2 commits intoapache:mainfrom Nov 4, 2023
Merged
[Scala] support scala collection jit serialization#1077chaokunyang merged 2 commits intoapache:mainfrom
chaokunyang merged 2 commits intoapache:mainfrom
Conversation
Collaborator
Author
|
With following naive tests, fury is faster and smaller than twill and JDK: Fury is 3X faster than twill/kryo and 6x faster than JDK. case class Foo(list: List[String])
object Test {
def main(args: Array[String]): Unit = {
val fury = Fury.builder().requireClassRegistration(false)
.withScalaOptimizationEnabled(true).build()
fury.getClassResolver.setSerializerFactory(new ScalaDispatcher)
val c = Foo(Range(1, 1000).map(x => String.valueOf(x)).toList)
val instantiator = new ScalaKryoInstantiator
instantiator.setRegistrationRequired(false)
val kryo = instantiator.newKryo()
var bytes: Array[Byte] = new Array[Byte](0)
val output = new Output(40000)
var start = System.currentTimeMillis()
for (_ <- Range(0, 200000)) {
output.clear()
kryo.writeClassAndObject(output, c)
bytes = output.toBytes
}
printf("twill time: %s, size %s\n", System.currentTimeMillis() - start, bytes.length)
val furySize = fury.serializeJavaObject(c).length
start = System.currentTimeMillis()
for (_ <- Range(0, 200000)) {
fury.serializeJavaObject(c)
}
printf("fury time: %s, size %s\n", System.currentTimeMillis() - start, furySize)
val bas = new ByteArrayOutputStream(200)
val objectOutputStream = new ObjectOutputStream(bas)
objectOutputStream.writeObject(c)
objectOutputStream.flush()
bytes = bas.toByteArray
start = System.currentTimeMillis()
for (_ <- Range(0, 200000)) {
bas.reset()
val objectOutputStream = new ObjectOutputStream(bas)
objectOutputStream.writeObject(c)
objectOutputStream.flush()
}
printf("jdk time: %s, size %s\n", System.currentTimeMillis() - start, bytes.length)
}
}Benchmark result: twill time: 16855, size 4925
fury time: 6356, size 5039
jdk time: 34283, size 6390For following collection, Fury is 1.5X faster than twill/kryo and 9x faster than JDK: object Test {
def main(args: Array[String]): Unit = {
val fury = Fury.builder().requireClassRegistration(false)
.withScalaOptimizationEnabled(true).build()
fury.getClassResolver.setSerializerFactory(new ScalaDispatcher)
val c = Range(1, 1000).toList
val instantiator = new ScalaKryoInstantiator
instantiator.setRegistrationRequired(false)
val kryo = instantiator.newKryo()
var bytes: Array[Byte] = new Array[Byte](0)
var start = System.currentTimeMillis()
val output = new Output(40000)
for (_ <- Range(0, 200000)) {
output.clear()
kryo.writeClassAndObject(output, c)
bytes = output.toBytes
// println(bytes.length)
}
println(System.currentTimeMillis() - start + " " + bytes.length)
start = System.currentTimeMillis()
for (_ <- Range(0, 200000)) {
fury.serialize(c)
}
println(System.currentTimeMillis() - start + " " + fury.serialize(c).length)
start = System.currentTimeMillis()
for (_ <- Range(0, 200000)) {
val bas = new ByteArrayOutputStream(200)
val objectOutputStream = new ObjectOutputStream(bas)
objectOutputStream.writeObject(c)
objectOutputStream.flush()
}
val x = new ByteArrayOutputStream(200)
val objectOutputStream = new ObjectOutputStream(x)
objectOutputStream.writeObject(c)
objectOutputStream.flush()
bytes = x.toByteArray
println(System.currentTimeMillis() - start + " " + bytes.length)
}
}Benchmark result: twill time: 5935, size 2938
fury time: 4076, size 2060
jdk time: 37672, size 10479@pjfanning The benchmark results seems pretty promising. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What do these changes do?
ScalaDispatcherto intercept all scala map/seq/set types.Related issue number
Closes #1076
#765
Check code requirements