Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5ccd04c3 authored by Tim Murray's avatar Tim Murray
Browse files

DynamicCodeLoggingService: avoid object churn

Recreating Matchers seems to incur a large memory cost until GC. Reuse
the Matcher and reset it to avoid the worst of this.

Test: atest DynamicCodeLoggerIntegrationTests
Bug: 178402808
Change-Id: I959a5a6eb92366495cf343116636703d1e752742
parent e7ce67f4
Loading
Loading
Loading
Loading
+4 −2
Original line number Original line Diff line number Diff line
@@ -234,7 +234,7 @@ public class DynamicCodeLoggingService extends JobService {


                List<EventLog.Event> events = new ArrayList<>();
                List<EventLog.Event> events = new ArrayList<>();
                EventLog.readEvents(tags, events);
                EventLog.readEvents(tags, events);

                Matcher matcher = EXECUTE_NATIVE_AUDIT_PATTERN.matcher("");
                for (int i = 0; i < events.size(); ++i) {
                for (int i = 0; i < events.size(); ++i) {
                    if (mAuditWatchingStopRequested) {
                    if (mAuditWatchingStopRequested) {
                        Log.w(TAG, "Stopping AuditWatchingJob run at scheduler request");
                        Log.w(TAG, "Stopping AuditWatchingJob run at scheduler request");
@@ -259,7 +259,9 @@ public class DynamicCodeLoggingService extends JobService {


                    // And then use a regular expression to verify it's one of the messages we're
                    // And then use a regular expression to verify it's one of the messages we're
                    // interested in and to extract the path of the file being loaded.
                    // interested in and to extract the path of the file being loaded.
                    Matcher matcher = EXECUTE_NATIVE_AUDIT_PATTERN.matcher(message);
                    // Reuse the Matcher to avoid unnecessary string garbage caused by libcore's
                    // regex matching.
                    matcher.reset(message);
                    if (!matcher.matches()) {
                    if (!matcher.matches()) {
                        continue;
                        continue;
                    }
                    }