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

feat(java): decoder add cache #1684

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

LiangliangSui
Copy link
Contributor

What does this PR do?

org.apache.fury.meta.Encoders adds cache to decoder and uses hashCode as key.

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

Signed-off-by: LiangliangSui <coolsui.coding@gmail.com>
Signed-off-by: LiangliangSui <coolsui.coding@gmail.com>
typeName, k -> TYPE_NAME_ENCODER.encode(typeName, typeNameEncodings));
}

public static String decodeFieldName(long hashCode, byte[] bytes, MetaString.Encoding encoding) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hashcode is an internal optimization, maybe we shouldn't make it pubic as an API for meta string encoder

@chaokunyang
Copy link
Collaborator

chaokunyang commented Jun 12, 2024

Hi @LiangliangSui , meta string encoding is not in critical path, we don't need to cache it. And we've alreadly have cache in ClassResolver

@LiangliangSui
Copy link
Contributor Author

Hi @LiangliangSui , meta string encoding is not in critical path, we don't need to cache it. And we've alreadly have cache in ClassResolver

The meta string encoding cache is already implemented in org.apache.fury.meta.Encoders. I just moved them a bit. Then I implemented the decode cache based on the meta string encoding cache.

@LiangliangSui
Copy link
Contributor Author

Why is meta string encoding not in the critical path? I see that encoding is cached in Encoders, maybe decoding needs similar optimization?

@chaokunyang
Copy link
Collaborator

Why is meta string encoding not in the critical path? I see that encoding is cached in Encoders, maybe decoding needs similar optimization?

It's encoded only once and cached in ClassResolver

@chaokunyang
Copy link
Collaborator

Is there a way to add cache for decode and didn't introduce API like hashcode stuff?

@LiangliangSui
Copy link
Contributor Author

Is there a way to add cache for decode and didn't introduce API like hashcode stuff?

I also thought about what you said, we can only establish an association with String through (byte[] encodedData, Encoding encoding), but the best way to integrate (byte[] encodedData, Encoding encoding) is to use hashcode, and this can also avoid the secondary calculation of (byte[] encodedData, Encoding encoding)

@chaokunyang
Copy link
Collaborator

The hashcode should not be added to MetaString API, it's really an internal implementation of class resolution

@LiangliangSui
Copy link
Contributor Author

Perhaps we can use (byte[] encodedData, Encoding encoding) to construct an incomplete MetaString, and then use MetaString as the key and String as the value.

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.

None yet

2 participants