fury icon indicating copy to clipboard operation
fury copied to clipboard

Big Bean compile take too long time

Open DemonJun opened this issue 1 year ago • 2 comments

Search before asking

  • [X] I had searched in the issues and found no similar issues.

Version

jdk: 17 fury: 0.4.1

Component(s)

Java

Minimal reproduce step

Create a bean containing 350 fields. The first serialization takes nearly 40 seconds. image

What did you expect to see?

Reduce time, or can be pre-compiled

What did you see instead?

Reduce time, or can be pre-compiled

Anything Else?

No response

Are you willing to submit a PR?

  • [ ] I'm willing to submit a PR!

DemonJun avatar Jan 05 '24 09:01 DemonJun

You can invoke Fury to generate serializer code to java files first, then compile it with your project together:

BaseObjectCodecBuilder codecBuilder = new ObjectCodecBuilder(cls, fury);
String code = codecBuilder.genCode();
Files.write(new File(codecBuilder.codecQualifiedClassName(cls).replace(".", "/") + ".java").toPath(),
      code.getBytes(StandardCharsets.UTF_8));

chaokunyang avatar Jan 05 '24 09:01 chaokunyang

Async compilation can be used for such cases too, it will compile generate serializer in background, and the serialization will use intepreter serializer before compilation finishes:

Fury fury=Fury.builder()
  .withLanguage(Language.JAVA)
  // enable reference tracking for shared/circular reference.
  // Disable it will have better performance if no duplicate reference.
  .withRefTracking(false)
  .withCompatibleMode(CompatibleMode.SCHEMA_CONSISTENT)
  // enable type forward/backward compatibility
  // disable it for small size and better performance.
  // .withCompatibleMode(CompatibleMode.COMPATIBLE)
  // enable async multi-threaded compilation.
  .withAsyncCompilation(true)
  .build();

chaokunyang avatar Jan 05 '24 11:01 chaokunyang