'Android method performance suddnely slow after upgrade from Marshmallow to Nougat

I have been developing a game, using a Samsung Galaxy S6 running Marshmallow as one of my development devices. After the phone upgraded itself to Nougat, a method which had taken 6ms on average to execute suddenly takes 40-70 ms. Other methods in my code are similarly affected -- the code seems to have slowed across the board.

Running the same build (the debug build) on a Yifang tablet running Marshmallow (from a clearance endcap at Walmart) still runs the method at about 8 ms. Systrace doesn't seem to show any problems other than that my code's thread is simply running for a long time. Under a profiler, the method runs at about 200 ms in both environments, and did on the Samsung under Marshmallow as well. The only difference is that AtomicLong.compareAndSwap() in java.util.Random.next() seems to take longer (might be blocking) and ArrayList.ensureExlicitCapacity()/ArrayList.grow() also appear to take longer.

The app has a UIThread, a second thread where I do all of my work, and a couple of Binder threads which Android adds.

I'm not so much looking for anyone to solve my performance issue, just wondering if anyone else has had the same problem since upgrading to Nougat, and what are some other tools I can use to try to find the problem?



Solution 1:[1]

Under Android Nougat, ART now runs JIT optimization at execution time instead of installation time. While I'm sure it speeds up installations and software updates, the first trip through a path in the code (and sometimes subsequent trips through that path) pays a big price in performance.

Fortunately, there is a way to run the JIT optimizations for an app via an adb command:

adb shell cmd package compile -m speed -f package-name

This command is described in a little more detail here.

After running this command, performance is what I would expect on my device.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rein DeBock