This is an automated email from the ASF dual-hosted git repository.
chaokunyang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-fury.git
The following commit(s) were added to refs/heads/main by this push:
new 73b5ef93 chore(java): reduce fury caller stack (#1496)
73b5ef93 is described below
commit 73b5ef9350125b9dae9af8c1ef1bc4a7b93c946a
Author: Shawn Yang <[email protected]>
AuthorDate: Sat Apr 13 14:22:41 2024 +0800
chore(java): reduce fury caller stack (#1496)
<!--
**Thanks for contributing to Fury.**
**If this is your first time opening a PR on fury, you can refer to
[CONTRIBUTING.md](https://github.com/apache/incubator-fury/blob/main/CONTRIBUTING.md).**
Contribution Checklist
- The **Apache Fury (incubating)** community has restrictions on the
naming of pr titles. You can also find instructions in
[CONTRIBUTING.md](https://github.com/apache/incubator-fury/blob/main/CONTRIBUTING.md).
- Fury has a strong focus on performance. If the PR you submit will have
an impact on performance, please benchmark it first and provide the
benchmark result here.
-->
## What does this PR do?
reduce fury caller stack
<!-- Describe the purpose of this PR. -->
## Related issues
<!--
Is there any related issue? Please attach here.
- #xxxx0
- #xxxx1
- #xxxx2
-->
## Does this PR introduce any user-facing change?
<!--
If any user-facing interface changes, please [open an
issue](https://github.com/apache/incubator-fury/issues/new/choose)
describing the need to do so and update the document if necessary.
-->
- [ ] Does this PR introduce any public API change?
- [ ] Does this PR introduce any binary protocol compatibility change?
## Benchmark
<!--
When the PR has an impact on performance (if you don't know whether the
PR will have an impact on performance, you can submit the PR first, and
if it will have impact on performance, the code reviewer will explain
it), be sure to attach a benchmark data here.
-->
---
.../src/main/java/org/apache/fury/Fury.java | 45 ++++++++++------------
1 file changed, 21 insertions(+), 24 deletions(-)
diff --git a/java/fury-core/src/main/java/org/apache/fury/Fury.java
b/java/fury-core/src/main/java/org/apache/fury/Fury.java
index 90b31913..c848faef 100644
--- a/java/fury-core/src/main/java/org/apache/fury/Fury.java
+++ b/java/fury-core/src/main/java/org/apache/fury/Fury.java
@@ -94,6 +94,7 @@ public final class Fury implements BaseFury {
private static final byte isCrossLanguageFlag = 1 << 2;
private static final byte isOutOfBandFlag = 1 << 3;
private static final boolean isLittleEndian = ByteOrder.nativeOrder() ==
ByteOrder.LITTLE_ENDIAN;
+ private static final byte BITMAP = isLittleEndian ? isLittleEndianFlag : 0;
private static final int BUFFER_SIZE_LIMIT = 128 * 1024;
private final Config config;
@@ -220,31 +221,20 @@ public final class Fury implements BaseFury {
@Override
public MemoryBuffer serialize(MemoryBuffer buffer, Object obj,
BufferCallback callback) {
- this.bufferCallback = callback;
- int maskIndex = buffer.writerIndex();
- // 1byte used for bit mask
- buffer.ensure(maskIndex + 1);
- buffer.writerIndex(maskIndex + 1);
- byte bitmap = 0;
+ byte bitmap = BITMAP;
+ if (language != Language.JAVA) {
+ bitmap |= isCrossLanguageFlag;
+ }
if (obj == null) {
bitmap |= isNilFlag;
- buffer.putByte(maskIndex, bitmap);
+ buffer.writeByte(bitmap);
return buffer;
}
- // set endian.
- if (isLittleEndian) {
- bitmap |= isLittleEndianFlag;
- }
- if (language != Language.JAVA) {
- // set reader as x_lang.
- bitmap |= isCrossLanguageFlag;
- // set writer language.
- buffer.writeByte((byte) Language.JAVA.ordinal());
- }
- if (bufferCallback != null) {
+ if (callback != null) {
bitmap |= isOutOfBandFlag;
+ bufferCallback = callback;
}
- buffer.putByte(maskIndex, bitmap);
+ buffer.writeByte(bitmap);
try {
jitContext.lock();
if (depth != 0) {
@@ -253,6 +243,7 @@ public final class Fury implements BaseFury {
if (language == Language.JAVA) {
write(buffer, obj);
} else {
+ buffer.writeByte((byte) Language.JAVA.ordinal());
xserializeInternal(buffer, obj);
}
return buffer;
@@ -307,14 +298,20 @@ public final class Fury implements BaseFury {
}
private void write(MemoryBuffer buffer, Object obj) {
- if (config.shareMetaContext()) {
- int startOffset = buffer.writerIndex();
+ int startOffset = buffer.writerIndex();
+ boolean shareMetaContext = config.shareMetaContext();
+ if (shareMetaContext) {
buffer.writeInt32(-1); // preserve 4-byte for nativeObjects start
offsets.
- writeRef(buffer, obj);
+ }
+ // reduce caller stack
+ if (!refResolver.writeRefOrNull(buffer, obj)) {
+ ClassInfo classInfo = classResolver.getOrUpdateClassInfo(obj.getClass());
+ classResolver.writeClass(buffer, classInfo);
+ writeData(buffer, classInfo, obj);
+ }
+ if (shareMetaContext) {
buffer.putInt32(startOffset, buffer.writerIndex());
classResolver.writeClassDefs(buffer);
- } else {
- writeRef(buffer, obj);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]