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

perf(java): generate list fori loop instead of iterator loop for list serialization #1493

Merged

Conversation

chaokunyang
Copy link
Collaborator

@chaokunyang chaokunyang commented Apr 11, 2024

What does this PR do?

generate list fori loop instead of iterator loop for list serialization

Before this PR:

  private void sameElementClassWrite(MemoryBuffer memoryBuffer2, int value3, int value4, java.util.Collection collection, boolean value5) {
      boolean isDeclType = (value4 & 4) != 4;
      Serializer serializer1;
      if (isDeclType) {
          serializer1 = serializer0;
      } else {
          serializer1 = imageClassInfoHolder.getSerializer();
      }
      java.util.Iterator iter = collection.iterator();
      int i = 0;
      while (iter.hasNext()) {
          org.apache.fury.benchmark.data.Image elemValue = (org.apache.fury.benchmark.data.Image)iter.next();
          if (value5) {
              if ((elemValue == null)) {
                  memoryBuffer2.writeByte(((byte)-3));
              } else {
                  memoryBuffer2.writeByte(((byte)0));
                  serializer1.write(memoryBuffer2, elemValue);
              }
          } else {
              serializer1.write(memoryBuffer2, elemValue);
          }
          i++;
      }
  }

image

With this PR:

  private void sameElementClassWrite(MemoryBuffer memoryBuffer2, java.util.List list2, int value3, int value4, boolean value5) {
      boolean isDeclType = (value3 & 4) != 4;
      Serializer serializer1;
      if (isDeclType) {
          serializer1 = serializer0;
      } else {
          serializer1 = imageClassInfoHolder.getSerializer();
      }
      for (int i = 0; i < value4; i+=1) {
        Object object = list2.get(i);
        org.apache.fury.benchmark.data.Image castedValue = (org.apache.fury.benchmark.data.Image)object;
        if (value5) {
            if ((castedValue == null)) {
                memoryBuffer2.writeByte(((byte)-3));
            } else {
                memoryBuffer2.writeByte(((byte)0));
                serializer1.write(memoryBuffer2, castedValue);
            }
        } else {
            serializer1.write(memoryBuffer2, castedValue);
        }
      }
  }

image

Related issues

Does this PR introduce any user-facing change?

  • Does this PR introduce any public API change?
  • Does this PR introduce any binary protocol compatibility change?

Benchmark

Before:
Benchmark                              (bufferType)   (objectType)  (references)   Mode  Cnt        Score        Error  Units
UserTypeSerializeSuite.fury_serialize         array  MEDIA_CONTENT         false  thrpt   30  3617413.349 ± 140849.598  ops/s

After:
Benchmark                              (bufferType)   (objectType)  (references)   Mode  Cnt        Score       Error  Units
UserTypeSerializeSuite.fury_serialize         array  MEDIA_CONTENT         false  thrpt   50  3795239.909 ± 77404.887  ops/s

@chaokunyang
Copy link
Collaborator Author

chaokunyang commented Apr 11, 2024

@theweipeng @LiangliangSui coul you help review this PR?

Copy link
Contributor

@LiangliangSui LiangliangSui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

@chaokunyang chaokunyang merged commit 10ee947 into apache:main Apr 11, 2024
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants