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

Prevent trace strings from getting created when tracing is disabled #2494

Merged
merged 1 commit into from
Apr 13, 2024

Conversation

uni-cstar
Copy link
Contributor

@uni-cstar uni-cstar closed this Apr 11, 2024
@uni-cstar uni-cstar reopened this Apr 11, 2024
@uni-cstar uni-cstar changed the base branch from master to gpeal/time-stretch-work-area April 11, 2024 08:54
@uni-cstar uni-cstar changed the base branch from gpeal/time-stretch-work-area to master April 11, 2024 08:55
Copy link
Collaborator

@gpeal gpeal left a comment

Choose a reason for hiding this comment

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

I'd be surprised if this makes a meaningful impact with all of the ART optimizations and background GC improvements over the years but this seems like a reasonable optimization.

@@ -112,8 +128,7 @@ protected float getInterpolatedCurrentKeyframeProgress() {
Keyframe<K> keyframe = getCurrentKeyframe();
// Keyframe should not be null here but there seems to be a Xiaomi Android 10 specific crash.
// https://github.com/airbnb/lottie-android/issues/2050
// https://github.com/airbnb/lottie-android/issues/2483
if (keyframe == null || keyframe.isStatic() || keyframe.interpolator == null) {
if (keyframe == null || keyframe.isStatic()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's leave this PR to a single task. Could you revert this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I found this issue was actually caused by virtual machine optimizations. I tracked memory allocations using the ‘Profiler’ tools from Android stuido and observed a significant number of StringBuilder instances being created at the points where beginSection and endSection methods were called. When I tested the code of my PR, these StringBuilder instances no longer appeared, and the memory stabilized without causing frequent garbage collection.
My test code is follow,I just provided an INFINITE LottieAnimationView in the layout, and didn't do anything else。

<com.airbnb.lottie.LottieAnimationView
                    android:id="@+id/assetView0"
                    android:layout_width="100dp"
                    android:layout_height="100dp"
                    app:lottie_autoPlay="true"
                    app:lottie_fileName="figure/data.json"
                    app:lottie_imageAssetsFolder="figure/images"
                    app:lottie_repeatCount="-1"/>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am Chinese and my English is not very good, so I may not fully understand your meaning or be able to respond clearly. I hope you can bear with me.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This comment is specifically referring to the addition you made here for keyframe.interpolator == null which seems unrelated to the rest of the code in this PR.

@uni-cstar
Copy link
Contributor Author

uni-cstar commented Apr 13, 2024 via email

Copy link

Snapshot Tests
API 23: Report Diff
API 31: Report Diff

@gpeal gpeal changed the title fix: Correct the frequent GC issues caused by L.beginSection and L.en… Prevent trace strings from getting created when tracing is disabled Apr 13, 2024
@gpeal gpeal merged commit aebf9bc into airbnb:master Apr 13, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants