yggdrasil-network / yggdrasil-android

Reference implementation for connecting to the Yggdrasil Network from Android devices
MIT License
107 stars 18 forks source link

Change API to save memory #25

Closed Revertron closed 1 year ago

Revertron commented 1 year ago

Currently, we create and free a lot of byte-array objects when working with TUN.

  1. The go-library is creating byte-array for every packet that is read. https://github.com/yggdrasil-network/yggdrasil-android/blob/main/app/src/main/java/eu/neilalexander/yggdrasil/PacketTunnelProvider.kt#L204
  2. We create a new array from slice to write to go-library. https://github.com/yggdrasil-network/yggdrasil-android/blob/main/app/src/main/java/eu/neilalexander/yggdrasil/PacketTunnelProvider.kt#L229

The memory diagram shows that there are a lot of GC runs when I run speed-test in browser. image

I propose that we change API to use single byte array in each case. But we need to add start and length parameters for read() and write() methods.

Revertron commented 1 year ago

Hmmm, this change increases upload speed from 9-20MBps to about 160-200Mbps :))

The speedtest shows that it starts on about 20Mbps and goes down to 9Mbps till the end. And after the fix it goes to 200.

I will prepare a PR to yggdrasil-go and here as well.