Deep nested structure results in "Method too large" error during scalac compilation
See original GitHub issueHi,
I’ve got this error message
scalac: Error while emitting io/univalence/avro_serde/Main$
Method too large: io/univalence/avro_serde/Main$.main ([Ljava/lang/String;)V
For the following IDL: https://gist.github.com/fsarradin/da8049e388e39de8e34ba17d24b54457
And for this code
package io.univalence.avro_serde
import com.sksamuel.avro4s.JsonFormat
import com.sksamuel.avro4s.kafka.GenericSerde
import test.entity.Entity
object Main {
def main(args: Array[String]): Unit = {
val entitySerde = new GenericSerde[Entity](JsonFormat)
println(entitySerde)
}
}
Do you know why I got this message and how to avoid it?
I’m using
- Avro4s 4.0.0
- Scala 2.13.3
- SBT 1.3.13
- SBT-AvroHugger 2.0.0-RC22
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (6 by maintainers)
Top Results From Across the Web
How to circumvent the "Method too large" error in Java ...
In this case, the problem is that a single method can consist of at most 65536 bytes of bytecodes. (See the JVM spec)....
Read more >java.lang.RuntimeException: Method code too large!
I am working on a scala-internal DSL that "serialize" its data structures into scala code that get's interpreted back from files to generate...
Read more >Speeding Up Compilation Time with scalac-profiling
I use the plugin to speed up the compile times of a Bloop module by 8x. The analysis and optimizations here presented can...
Read more >“Code too large” Compilation Error in Java | Baeldung
When a Java method exceeds 65535 bytes, we get the compilation error, “code too large”. In this article, we'll discuss why this error...
Read more >Chapter 5. Using implicits to write expressive code - Scala in ...
The implicit system in Scala allows the compiler to adjust code using a well-defined lookup mechanism ... We then define the tmp method...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
avro4s builds schemas using
SchemaFor
so you could split out the three types, and then add an implicit schema for where you need it.If you split up the macro by introducing intermediate schemas it should work.
Eg, if you had
then you can do something like:
This should force the compiler to generate smaller macro methods.
You can try by picking 2 or 3 large nested types and pulling out the implicits. You need to do it for schemas and encoders / decoders.