fury icon indicating copy to clipboard operation
fury copied to clipboard

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

Open LouisLou2 opened this issue 4 months ago • 1 comments

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

  • #2435

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 avatar Aug 06 '25 13:08 LouisLou2

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 avatar Aug 20 '25 07:08 chaokunyang