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

Commit bcc0b914 authored by John Reck's avatar John Reck
Browse files

Fix performance regression in textclassifier

DeviceConfig is far too slow to be used here, so
disable it.

Test: trace calculator launch
Change-Id: I6b7ab56e4015448ee068deb49e7f6fa133fea53c
parent a3151aa9
Loading
Loading
Loading
Loading
+36 −16
Original line number Diff line number Diff line
@@ -33,6 +33,10 @@ public final class ConfigParser {

    private final KeyValueListParser mParser;

    // TODO: Re-enable DeviceConfig when it has reasonable performance or just delete the
    // option of using DeviceConfig entirely.
    static final boolean ENABLE_DEVICE_CONFIG = false;

    public ConfigParser(@Nullable String textClassifierConstants) {
        final KeyValueListParser parser = new KeyValueListParser(',');
        try {
@@ -48,39 +52,55 @@ public final class ConfigParser {
     * Reads a boolean flag.
     */
    public boolean getBoolean(String key, boolean defaultValue) {
        if (ENABLE_DEVICE_CONFIG) {
            return DeviceConfig.getBoolean(
                    DeviceConfig.NAMESPACE_TEXTCLASSIFIER,
                    key,
                    mParser.getBoolean(key, defaultValue));
        } else {
            return mParser.getBoolean(key, defaultValue);
        }
    }

    /**
     * Reads an integer flag.
     */
    public int getInt(String key, int defaultValue) {
        if (ENABLE_DEVICE_CONFIG) {
            return DeviceConfig.getInt(
                    DeviceConfig.NAMESPACE_TEXTCLASSIFIER,
                    key,
                    mParser.getInt(key, defaultValue));
        } else {
            return mParser.getInt(key, defaultValue);
        }
    }

    /**
     * Reads a float flag.
     */
    public float getFloat(String key, float defaultValue) {
        if (ENABLE_DEVICE_CONFIG) {
            return DeviceConfig.getFloat(
                    DeviceConfig.NAMESPACE_TEXTCLASSIFIER,
                    key,
                    mParser.getFloat(key, defaultValue));
        } else {
            return mParser.getFloat(key, defaultValue);
        }
    }

    /**
     * Reads a string flag.
     */
    public String getString(String key, String defaultValue) {
        if (ENABLE_DEVICE_CONFIG) {
            return DeviceConfig.getString(
                    DeviceConfig.NAMESPACE_TEXTCLASSIFIER,
                    key,
                    mParser.getString(key, defaultValue));
        } else {
            return mParser.getString(key, defaultValue);
        }
    }
}
+9 −5
Original line number Diff line number Diff line
@@ -197,8 +197,10 @@ public final class TextClassificationManager {
            if (mSettingsObserver != null) {
                getApplicationContext().getContentResolver()
                        .unregisterContentObserver(mSettingsObserver);
                if (ConfigParser.ENABLE_DEVICE_CONFIG) {
                    DeviceConfig.removeOnPropertyChangedListener(mSettingsObserver);
                }
            }
        } finally {
            super.finalize();
        }
@@ -292,11 +294,13 @@ public final class TextClassificationManager {
                    Settings.Global.getUriFor(Settings.Global.TEXT_CLASSIFIER_CONSTANTS),
                    false /* notifyForDescendants */,
                    this);
            if (ConfigParser.ENABLE_DEVICE_CONFIG) {
                DeviceConfig.addOnPropertyChangedListener(
                        DeviceConfig.NAMESPACE_TEXTCLASSIFIER,
                        ActivityThread.currentApplication().getMainExecutor(),
                        this);
            }
        }

        @Override
        public void onChange(boolean selfChange) {
+5 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import androidx.test.runner.AndroidJUnit4;

import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;

@@ -58,6 +59,7 @@ public class ConfigParserTest {
    }

    @Test
    @Ignore // TODO: Re-enable once ConfigParser#ENABLE_DEVICE_CONFIG is finalized
    public void getBoolean_deviceConfig() {
        DeviceConfig.setProperty(
                DeviceConfig.NAMESPACE_TEXTCLASSIFIER,
@@ -77,6 +79,7 @@ public class ConfigParserTest {
    }

    @Test
    @Ignore // TODO: Re-enable once ConfigParser#ENABLE_DEVICE_CONFIG is finalized
    public void getInt_deviceConfig() {
        DeviceConfig.setProperty(
                DeviceConfig.NAMESPACE_TEXTCLASSIFIER,
@@ -94,6 +97,7 @@ public class ConfigParserTest {
    }

    @Test
    @Ignore // TODO: Re-enable once ConfigParser#ENABLE_DEVICE_CONFIG is finalized
    public void getFloat_deviceConfig() {
        DeviceConfig.setProperty(
                DeviceConfig.NAMESPACE_TEXTCLASSIFIER,
@@ -111,6 +115,7 @@ public class ConfigParserTest {
    }

    @Test
    @Ignore // TODO: Re-enable once ConfigParser#ENABLE_DEVICE_CONFIG is finalized
    public void getString_deviceConfig() {
        DeviceConfig.setProperty(
                DeviceConfig.NAMESPACE_TEXTCLASSIFIER,