Skip to content
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

refactor(firebase_performance): refactor underlying implementation for the "handler system" so the handlers are generated on native side #9334

Merged
merged 20 commits into from
Dec 23, 2022

Conversation

russellwheatley
Copy link
Member

@russellwheatley russellwheatley commented Aug 10, 2022

Description

Removed the handler system on the Method channel. android & iOS track the HttpMetric & Trace instances on their implementations. This makes it much safer and easier to understand.

Something that I wasn't sure on was behaviour for hot restart. Implementation will now stop() and remove all HttpMetric & Trace instances on a hot restart. android & iOS.

I've also added additional e2e tests for start() and stop(). You can now start() and stop() HttpMetric & Trace instances as many times as you wish (They only go to the native side on the first start() and stop(). So no side effects to calling multiple times.)

To clarify, HttpMetric & Trace are a one time only transaction. Once stopped, they are removed on the native side.

I've also committed like the following to make it a bit easier to follow:

  1. Dart (method channel implementation, e2e tests, unit tests)
  2. iOS
  3. android
  4. example app (last 2 commits)

Related Issues

fixes #7465, #7447

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]).
This will ensure a smooth and quick review process. Updating the pubspec.yaml and changelogs is not required.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See Contributor Guide).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (melos run analyze) does not report any problems on my PR.
  • I read and followed the Flutter Style Guide.
  • I signed the CLA.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change.
  • No, this is not a breaking change.

@russellwheatley russellwheatley marked this pull request as ready for review August 11, 2022 09:32
@russellwheatley russellwheatley added plugin: performance platform: android Issues / PRs which are specifically for Android. platform: ios Issues / PRs which are specifically for iOS. labels Aug 17, 2022
Copy link

@rwrz rwrz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did a quick code review, everything seems fine to me.
I will start to use it, here on my dev machine, to ensure nothing is missing. Thanks for the great work!

@rwrz
Copy link

rwrz commented Sep 27, 2022

btw, the question is, do you need someone to review it?

@russellwheatley
Copy link
Member Author

russellwheatley commented Sep 28, 2022

@rwrz - thanks! We'll aim to get this PR merged at some point next week hopefully 🤞. In the mean time, if you do have any feedback could you update this channel, please? 😄

To your question, if you wish to leave a review, that would be awesome! The more eyes the better 💪 . However, the PR requires 2 approvals from contributors before it can be merged 👌

@russellwheatley
Copy link
Member Author

@rwrz Have you started to use this in your project?

@rwrz
Copy link

rwrz commented Oct 6, 2022

Yes. We were using it in DEV for a while, and now it is going to production.

Copy link
Contributor

@Lyokone Lyokone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I'm wondering if we should make it a major version since it's a major rewriting of the firebase_performance plugin? It would also help version it properly and revert back to a previous version if anything would go wrong?

@russellwheatley
Copy link
Member Author

@Lyokone Agreed, I must've missed the (!) in the title 😓

@russellwheatley russellwheatley changed the title refactor(firebase_performance): refactor "handler system" so the handlers are generated on native side refactor(firebase_performance)!: refactor "handler system" so the handlers are generated on native side Oct 6, 2022
# Conflicts:
#	packages/firebase_performance/firebase_performance/example/lib/firebase_config.dart
@Ehesp
Copy link
Member

Ehesp commented Oct 25, 2022

I'm a bit confused by the ! in the title - what about this change makes it breaking? It's mentioned about hot reload but could someone explain how that is effected here?

this._url,
this._httpMethod,
) : super();

final int _methodChannelHandle;
final int _httpMetricHandle;
late final int _httpMetricHandle;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this not be simplified? Instead use int? _httpMetricHandle within the start/stop methods to detect whether it's been started/stopped already?

Copy link
Member Author

@russellwheatley russellwheatley Oct 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated implementation, but you still need an additional boolean to check if it has ran once. Otherwise, you would set _httpMetricHandle to null again and you would be able to start/stop again.

@russellwheatley
Copy link
Member Author

russellwheatley commented Oct 25, 2022

@Ehesp I've made it a breaking change because of the following reasons:

  1. It will remove all Trace & HttpMetric instances on a hot reload (admittedly, probably not a good reason to make it a breaking change).
  2. Previously, you could call start() stop() and it would keep hitting the native side creating new instance (or throwing exceptions as the case may be). Now, we stop it from hitting native and creating new instances.
  3. It's a complete refactor of existing underlying implementation. Is it worth the risk not making it a breaking change?

@rwrz
Copy link

rwrz commented Oct 27, 2022

@russellwheatley I had to switch back to "master". Your implementation is lacking the possibility to create "custom traces".

MissingPluginException(No implementation found for method FirebasePerformance#newTrace on channel plugins.flutter.io/firebase_performance

@russellwheatley
Copy link
Member Author

@rwrz you must be using the old version because that method channel call (FirebasePerformance#newTrace) does not exist on this PR. See here.

You can also check the CI which is running these Firebase Performance e2e tests for custom traces.

Successful CI run here

# Conflicts:
#	packages/firebase_performance/firebase_performance/example/.firebaserc
#	packages/firebase_performance/firebase_performance/example/android/app/google-services.json
#	packages/firebase_performance/firebase_performance/example/ios/Runner.xcodeproj/project.pbxproj
#	packages/firebase_performance/firebase_performance/example/ios/firebase_app_id_file.json
#	packages/firebase_performance/firebase_performance/example/lib/firebase_options.dart
#	packages/firebase_performance/firebase_performance/example/lib/main.dart
@carlosfiori
Copy link

Any update on this?

@russellwheatley russellwheatley changed the title refactor(firebase_performance)!: refactor "handler system" so the handlers are generated on native side refactor(firebase_performance): refactor underlying implementation for the "handler system" so the handlers are generated on native side Dec 23, 2022
@russellwheatley russellwheatley merged commit 08a4be6 into master Dec 23, 2022
@russellwheatley russellwheatley deleted the @russell/perf-7465 branch December 23, 2022 14:45
@firebase firebase locked and limited conversation to collaborators Jan 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
platform: android Issues / PRs which are specifically for Android. platform: ios Issues / PRs which are specifically for iOS. plugin: performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐛 [FirebasePerformance] java.lang.IllegalArgumentException: Object for handle already exists: 3
6 participants