-
-
Notifications
You must be signed in to change notification settings - Fork 276
enh: refactor init to use JNI/FFI
#3324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Instructions and example for changelogPlease add an entry to Example: ## Unreleased
### Features
- refactor `init` to use JNI/FFI ([#3324](https://github.com/getsentry/sentry-dart/pull/3324))If none of the above apply, you can opt out of this check by adding |
🚨 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:
|
iOS Performance metrics 🚀
|
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 6f47800 | 1247.52 ms | 1259.37 ms | 11.85 ms |
| 6bcdc99 | 1257.16 ms | 1264.96 ms | 7.79 ms |
| 765aa8b | 1259.09 ms | 1269.90 ms | 10.82 ms |
| 73a3c38 | 1263.37 ms | 1277.90 ms | 14.53 ms |
| 0fb45d0 | 1273.24 ms | 1286.44 ms | 13.19 ms |
| aeb02f2 | 1244.29 ms | 1256.55 ms | 12.26 ms |
| f761369 | 1261.69 ms | 1277.82 ms | 16.12 ms |
| 0fb3800 | 1256.60 ms | 1266.28 ms | 9.68 ms |
| e04b24b | 1230.22 ms | 1233.90 ms | 3.67 ms |
| 1f639ee | 1252.43 ms | 1257.82 ms | 5.38 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 6f47800 | 7.86 MiB | 9.44 MiB | 1.58 MiB |
| 6bcdc99 | 5.53 MiB | 6.00 MiB | 479.95 KiB |
| 765aa8b | 7.86 MiB | 9.44 MiB | 1.58 MiB |
| 73a3c38 | 7.86 MiB | 9.44 MiB | 1.58 MiB |
| 0fb45d0 | 7.86 MiB | 9.44 MiB | 1.58 MiB |
| aeb02f2 | 7.86 MiB | 9.44 MiB | 1.58 MiB |
| f761369 | 7.86 MiB | 9.44 MiB | 1.58 MiB |
| 0fb3800 | 7.86 MiB | 9.44 MiB | 1.58 MiB |
| e04b24b | 5.53 MiB | 6.00 MiB | 480.00 KiB |
| 1f639ee | 5.53 MiB | 6.00 MiB | 479.95 KiB |
| if (!sentryFlutter.autoPerformanceTracingEnabled) { | ||
| return 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.
removing it here, we have this check in the Dart side
| final ObjCObjectBase Function(Object) _defaultObjcConverter = (obj) { | ||
| return switch (obj) { | ||
| bool b => b ? 1.toNSNumber() : 0.toNSNumber(), | ||
| bool b => NSNumberCreation.numberWithBool(b), |
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.
previous convert was wrong, it should've been using NSNumberCreation
init to use JNI/FFIinit to use JNI/FFI
| #endif | ||
| } | ||
|
|
||
| @objc(setBeforeSend:packages:integrations:) |
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.
Don't think we need different naming for objc, as this will never be called from Swift directly.
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.
This is so it's more explicit how the name is generated for objc
without it it's setBeforeSendWithOptions(...) by default
this took a lot of time away from me because I couldn't figure out why the app was crashing and it turns out I should've used setBeforeSendWithOptions in SentryFlutterPlugin.h when creating the bindings instead of only setBeforeSend.
In the end I decided to add this so it's explicit how it's converted
I don't mind reverting it, though I think it would be helpful for the future to be more specific
packages/flutter/ios/sentry_flutter/Sources/sentry_flutter/SentryFlutterPlugin.swift
Outdated
Show resolved
Hide resolved
packages/flutter/ios/sentry_flutter/Sources/sentry_flutter/SentryFlutterPlugin.swift
Show resolved
Hide resolved
packages/flutter/ios/sentry_flutter/Sources/sentry_flutter/SentryFlutterPlugin.swift
Outdated
Show resolved
Hide resolved
packages/flutter/ios/sentry_flutter/Sources/sentry_flutter_objc/SentryFlutterPlugin.h
Outdated
Show resolved
Hide resolved
| : e as Object | ||
| ], | ||
| List<dynamic> l => _deepConvertListNonNull(l), | ||
| _ => value as Object, |
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.
Also here, toObjCObject not needed?
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.
same comment as above, this function doesn't do any objc conversions
packages/flutter/lib/src/native/cocoa/sentry_native_cocoa_init.dart
Outdated
Show resolved
Hide resolved
| - '-I./temp/Sentry.framework/Headers/' | ||
| - '-I./temp/Sentry.framework/PrivateHeaders/' | ||
| - '-I./ios/sentry_flutter/Sources/sentry_flutter_objc/' | ||
| - -DFFIGEN=1 |
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.
What does this compiler option do?
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.
See ffigen_objc_imports.h
#ifdef FFIGEN
// Only included while running ffigen (provide paths in compiler-opts).
#import "PrivateSentrySDKOnly.h"
#import "Sentry-Swift.h"
#import "SentryOptions.h"
#import "SentryScope.h"
#endifif we dont have this it will complain when compiling the app. We only need these headers when we use ffigen
| high(resolutionScalingFactor: 1.0), | ||
| medium(resolutionScalingFactor: 1.0), | ||
| low(resolutionScalingFactor: 0.8); | ||
| high(resolutionScalingFactor: 1.0, level: 2), |
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.
Why the addition of level?
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.
so we can map it directly to cocoa quality:
quality: options.replay.quality.level,
alternatively we could remove it and just do it on the call site
packages/flutter/lib/src/native/cocoa/sentry_native_cocoa_init.dart
Outdated
Show resolved
Hide resolved
|
I'm currently working on optimizing the JNI bindings so it only creates bindings for fields and methods we specify |
📜 Description
💡 Motivation and Context
💚 How did you test it?
📝 Checklist
sendDefaultPiiis enabled🔮 Next steps