airbnb / lottie-android

Render After Effects animations natively on Android and iOS, Web, and React Native
http://airbnb.io/lottie/
Apache License 2.0
34.92k stars 5.4k forks source link

Correct the frequent GC issues caused by L.beginSection and L.endSection methods. #2493

Closed uni-cstar closed 4 months ago

uni-cstar commented 4 months ago

Lottie is supported and developed on nights and weekends. Issues from Lottie sponsors will be prioritized.

Is your feature request related to a problem? Please describe. The L.beginSection and L.endSection methods are used to record some trace information and are frequently called during the draw process. Although traceEnabled is by default false, L.beginSection and L.endSection methods do not perform any substantive logic. However, they generate a large number of strings at the method call sites, leading to frequent garbage collection issues (occurring continuously in a short period due to the excessively frequent invocation of draw).

Describe the solution you'd like Provide the isTraceEnabled method in the L class to return the value of the traceEnabled variable. Before calling the L.beginSection and L.endSection methods, first check if isTraceEnabled is true. If not, do not invoke them.

Describe alternatives you've considered You can use inline methods in Kotlin to handle calls to the trace method, but this change is quite significant and requires rewriting the source code in Kotlin.

uni-cstar commented 4 months ago

2494 fixed this.