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 4ed1ff4a perf(java): Reduce unsafePutPositiveVarInt bytecode size.
(#1490)
4ed1ff4a is described below
commit 4ed1ff4aa9892f0e5aab18876acf624c8adeec5f
Author: LiangliangSui <[email protected]>
AuthorDate: Thu Apr 11 18:19:14 2024 +0800
perf(java): Reduce unsafePutPositiveVarInt bytecode size. (#1490)
<!--
**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?
<!-- Describe the purpose of this PR. -->
Reduce unsafePutPositiveVarInt bytecode size from 192 to 151.
## Related issues
<!--
Is there any related issue? Please attach here.
- #xxxx0
- #xxxx1
- #xxxx2
-->
https://github.com/apache/incubator-fury/issues/1466
## 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.
-->
before

with this pr

Signed-off-by: LiangliangSui <[email protected]>
---
.../java/org/apache/fury/memory/MemoryBuffer.java | 28 ++++++++++------------
1 file changed, 13 insertions(+), 15 deletions(-)
diff --git
a/java/fury-core/src/main/java/org/apache/fury/memory/MemoryBuffer.java
b/java/fury-core/src/main/java/org/apache/fury/memory/MemoryBuffer.java
index b8e431cb..6dda1e78 100644
--- a/java/fury-core/src/main/java/org/apache/fury/memory/MemoryBuffer.java
+++ b/java/fury-core/src/main/java/org/apache/fury/memory/MemoryBuffer.java
@@ -1260,38 +1260,36 @@ public final class MemoryBuffer {
/**
* Caller must ensure there must be at least 8 bytes for writing, otherwise
the crash may occur.
*/
- public int unsafePutPositiveVarInt(int index, int v) {
+ public int unsafePutPositiveVarInt(int index, int value) {
// The encoding algorithm are based on kryo UnsafeMemoryOutput.writeVarInt
// varint are written using little endian byte order.
// This version should have better performance since it remove an index
update.
- long value = v;
long varInt = (value & 0x7F);
- value >>>= 7;
- if (value == 0) {
+ if (value >>> 7 == 0) {
UNSAFE.putByte(heapMemory, address + index, (byte) varInt);
return 1;
}
// bit 8 `set` indicates have next data bytes.
- varInt |= ((value & 0x7F) << 8) | 0x80;
- value >>>= 7;
- if (value == 0) {
+ // 0x3f80: 0b1111111 << 7
+ varInt |= (((value & 0x3f80) << 1) | 0x80);
+ if (value >>> 14 == 0) {
unsafePutInt(index, (int) varInt);
return 2;
}
- varInt |= ((value & 0x7F) << 16) | 0x8000;
- value >>>= 7;
- if (value == 0) {
+ // 0x1fc000: 0b1111111 << 14
+ varInt |= (((value & 0x1fc000) << 2) | 0x8000);
+ if (value >>> 21 == 0) {
unsafePutInt(index, (int) varInt);
return 3;
}
- varInt |= ((value & 0x7F) << 24) | 0x800000;
- value >>>= 7;
- if (value == 0) {
+ // 0xfe00000: 0b1111111 << 21
+ varInt |= ((value & 0xfe00000) << 3) | 0x800000;
+ if (value >>> 28 == 0) {
unsafePutInt(index, (int) varInt);
return 4;
}
- varInt |= ((value & 0x7F) << 32) | 0x80000000L;
- varInt &= 0xFFFFFFFFFL;
+ // 0xfe00000: 0b1111111 << 28
+ varInt |= ((value & 0x7f0000000L) << 4) | 0x80000000L;
unsafePutLong(index, varInt);
return 5;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]