Skip to content

refactor(java): [Don't Merge for Now]Modify the current memory manipulation to be compatible with Android#2445

Closed
LouisLou2 wants to merge 11 commits intoapache:mainfrom
LouisLou2:implement_another_memory_util
Closed

refactor(java): [Don't Merge for Now]Modify the current memory manipulation to be compatible with Android#2445
LouisLou2 wants to merge 11 commits intoapache:mainfrom
LouisLou2:implement_another_memory_util

Conversation

@LouisLou2
Copy link
Copy Markdown
Contributor

What does this PR do?

This commit refactors memory management logic as an initial step towards making the project compatible with the Android platform.

Key points:

  • This is an exploratory change to propose a potential solution. The design may require further refinement for clarity.
  • These changes are strictly limited to memory operations. Full Android support will require other modifications.
  • Detailed documentation explaining the rationale will be provided later.

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

@LouisLou2 LouisLou2 requested a review from chaokunyang as a code owner August 6, 2025 13:54
@LouisLou2 LouisLou2 force-pushed the implement_another_memory_util branch from 38b8c5e to 92be239 Compare August 7, 2025 14:54
@chaokunyang
Copy link
Copy Markdown
Collaborator

Andriod String seems be implemented as a native class, we can't get value and coder field from String object.

Here are two tricks to keep maxmimal performance:

  • Use public void getBytes (int srcBegin, int srcEnd, byte[] dst, int dstBegin) to get bytes for JDK9+
  • Use String.toCharArray for JDK8

Don't use String.charAt, it's much more slow than get chars array first and check by a loop. JVM can employ some optimzation for simple loops if it doesn't contains nested methods call

@chaokunyang chaokunyang closed this Dec 3, 2025
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.

2 participants