Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize codec-registration-serializer-check phase #155

Merged
merged 2 commits into from
May 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ Then, in the target project sbt shell, type `compile`. If the compilation finish
Remember to type `clean` after successful compilations.
Otherwise, incremental compilation might determine there is nothing to compile and won't run the plugin you are testing.

### Profiling

To profile akka-serialization-helper compiler plugin used in another project - follow instructions from https://www.lightbend.com/blog/profiling-jvm-applications
You might as well use any other profiler, but using https://github.com/jvm-profiling-tools/async-profiler with flamegraphs should be really effective and easy to achieve (+ no unexpected bugs / issues / errors).

### Code quality

Before committing, don't forget to type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ class SerializerCheckCompilerPluginComponent(
private var typesNotDumped = true
private val typesToCheck = mutable.Map[String, List[(String, String)]]().withDefaultValue(Nil)

override def newPhase(prev: Phase): Phase =
private lazy val classSweepFoundTypes = classSweep.foundTypes.toSet
private lazy val classSweepTypesToUpdate = classSweep.typesToUpdate.toSet

override def newPhase(prev: Phase): Phase = {
new StdPhase(prev) {
override def apply(unit: global.CompilationUnit): Unit = {
if (typesNotDumped) {
Expand All @@ -43,16 +46,14 @@ class SerializerCheckCompilerPluginComponent(
try {
val buffer = ByteBuffer.allocate(channel.size().toInt)
channel.read(buffer)
val ot = CodecRegistrationCheckerCompilerPlugin.parseCacheFile(buffer.rewind()).toSet
val ft = classSweep.foundTypes.toSet
val tu = classSweep.typesToUpdate.toSet
val out = ((ot -- tu) | ft).toList
val typesFromCacheFile = CodecRegistrationCheckerCompilerPlugin.parseCacheFile(buffer.rewind()).toSet
val outTypes = ((typesFromCacheFile -- classSweepTypesToUpdate) | classSweepFoundTypes).toList

val outData = out.map(x => x._1 + "," + x._2).sorted.reduceOption(_ + "\n" + _).getOrElse("")
val outData = outTypes.map(x => x._1 + "," + x._2).sorted.reduceOption(_ + "\n" + _).getOrElse("")
channel.truncate(0)
channel.write(ByteBuffer.wrap(outData.getBytes(StandardCharsets.UTF_8)))

typesToCheck ++= out.groupBy(_._1)
typesToCheck ++= outTypes.groupBy(_._1)
typesNotDumped = false
} finally {
lock.close()
Expand Down Expand Up @@ -112,6 +113,7 @@ class SerializerCheckCompilerPluginComponent(
.collect {
case x: Tree if x.tpe != null => x.tpe
}
.distinct
.groupBy(_.toString())
.filter(_._1.matches(filterRegex))
.map(_._2.head)
Expand All @@ -130,6 +132,7 @@ class SerializerCheckCompilerPluginComponent(
else
typeArgsBfs(next, acc)
}

val foundInSerializerTypesFqcns = typeArgsBfs(foundTypes.toSet).map(_.typeSymbol.fullName)

val missingFqcn = typesToCheck(fqcn).map(_._2).filterNot(foundInSerializerTypesFqcns)
Expand Down Expand Up @@ -165,4 +168,5 @@ class SerializerCheckCompilerPluginComponent(
}
}
}
}
}