-
-
Notifications
You must be signed in to change notification settings - Fork 246
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
refactor: use JNI for Android integration #2670
Conversation
iOS Performance metrics 🚀
|
Revision | Plain | With Sentry | Diff |
---|---|---|---|
a22e451 | 1248.37 ms | 1270.55 ms | 22.19 ms |
88e4bfd | 1236.44 ms | 1256.33 ms | 19.90 ms |
0db91cc | 1267.63 ms | 1279.69 ms | 12.06 ms |
90a08ea | 1260.45 ms | 1285.24 ms | 24.80 ms |
8de999e | 1267.51 ms | 1281.00 ms | 13.49 ms |
ba9c106 | 1241.76 ms | 1265.15 ms | 23.40 ms |
05933ac | 1258.37 ms | 1285.57 ms | 27.21 ms |
3334ac1 | 1259.22 ms | 1275.40 ms | 16.17 ms |
3a16179 | 1238.18 ms | 1255.62 ms | 17.44 ms |
c15867f | 1247.36 ms | 1264.63 ms | 17.26 ms |
App size
Revision | Plain | With Sentry | Diff |
---|---|---|---|
a22e451 | 8.42 MiB | 9.89 MiB | 1.47 MiB |
88e4bfd | 8.33 MiB | 9.64 MiB | 1.31 MiB |
0db91cc | 8.15 MiB | 9.15 MiB | 1018.56 KiB |
90a08ea | 8.38 MiB | 9.73 MiB | 1.36 MiB |
8de999e | 8.42 MiB | 9.88 MiB | 1.46 MiB |
ba9c106 | 8.32 MiB | 9.38 MiB | 1.06 MiB |
05933ac | 8.38 MiB | 9.78 MiB | 1.40 MiB |
3334ac1 | 8.10 MiB | 9.17 MiB | 1.08 MiB |
3a16179 | 8.38 MiB | 9.73 MiB | 1.35 MiB |
c15867f | 8.42 MiB | 9.91 MiB | 1.49 MiB |
🚨 Detected changes in high risk code 🚨High-risk code has higher potential to break the SDK and may be hard to test. To prevent severe bugs, apply the rollout process for releasing such changes and be extra careful when changing and reviewing these files:
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## v9 #2670 +/- ##
===========================================
+ Coverage 67.94% 88.38% +20.43%
===========================================
Files 15 261 +246
Lines 443 8890 +8447
===========================================
+ Hits 301 7857 +7556
- Misses 142 1033 +891 ☔ View full report in Codecov by Sentry. |
@HosseinYousefi do you mind taking a look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked the JNI related parts and overall LGTM with one small comment.
// Android Bitmap creation is a bit costly so we reuse it between captures. | ||
native.Bitmap? bitmap; | ||
|
||
final _nativeReplay = native.SentryFlutterPlugin$Companion(null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please open an issue for JNIgen to remove the synthetic "default constructor" marker added by the Kotlin compiler from the generated code and just pass null
.
// https://developer.android.com/reference/android/graphics/Bitmap#createBitmap(int,%20int,%20android.graphics.Bitmap.Config) | ||
// Note: in the currently generated API this may return null so we null-check below. | ||
bitmap ??= native.Bitmap.createBitmap$3( | ||
item.width, item.height, native.Bitmap$Config.ARGB_8888); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.ARGB_8888
creates a references which is not eagerly released.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing it out, I've actually had a suspicion that may be the case but it doesn't matter in this case as it's only executed once for each orientation change so it's fine if it's collected by GC
|
||
// Note, this is currently not unit-tested because mocking the JNI calls is | ||
// cumbersome, see https://github.com/dart-lang/native/issues/1794 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please let me know what your ideal mocking solution would look like in the issue.
import 'package:benchmarking/benchmarking.dart'; | ||
import 'package:flutter/foundation.dart'; | ||
|
||
Future<void> execute() async { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiousity, have you measured the perfomance improvement between the previous way of using method channels vs. using jni?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not per se. I have profiled it previously and with the new code and the biggest benefit we get is that we can now use Bitmap
directly from raw RGBA so we don't have to convert to PNG (which is in hundreds of milliseconds, even though it's async) and to write an intermediary file (two IO ops - write & read). So there really is no one-to-one comparison between the approaches.
Another benefit was being able to move the work to another isolate altogether. Actually, I need to check whether I can pass an Uint8List efficiently between isolates. Last time I checked it didn't work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't comment much on the jni parts but lgtm so far
Co-authored-by: Giancarlo Buenaflor <giancarlo_buenaflor@yahoo.com>
📜 Description
This is a first step towards migrating our Android plugin glue code to JNI (part of #1444).
Done in this PR:
package:jni
is in a nonstable release cycle (0.x) so there may be breaking changes even between minor releases.🔮 Next steps
💡 Motivation and Context
💚 How did you test it?
Manually & udpated tests
📝 Checklist
sendDefaultPii
is enabled