[Sony Xperia XZ2 Questions & Answers] mirhl:
So, after like 3 years of banging my head, I think I finally have a theory (52.0.A.3.27 is slightly newer than what was discussed here, but still).

Two years ago I realized storage was somehow involved (when you have more than 1-2GB free.. itches and hangs aren't exactly solved, but they are noticeably less consistent and persistent).

And last year I figured it def couldn't be some intensive wear leveling algorithm or something, but it had to be paging-related (because I noticed a little disk space was always getting freed after restarts, I could swear clearing all recent apps had eventually helped me once or twice, and despite the Running services screen having some uncharacteristic-but-neglectable swings the Memory menu was showing me way higher unaccounted hourly averages).

Though since nothing appeared to be really wrong, I wishy-washily just blamed some voodoo bug in LMK or zram and went on living.

Then yesterday, after an excruciatingly minutes-long period of inability to record smoothly even just a bloody telegram video message, I rushed as fast as I could to run adb and I think I could finally nail this down once and for all.

Spoiler content hidden.

System UI cpu usage easily grabs attention.. but, you know, it's only using up two cores tops? And whatever horrors may be happening to it on the phone, that still cannot explain individual foreground apps sucking too.

Hell, you could even argue it's actually more sketchy that at half past six in the afternoon Sleep as Android somehow decides it's time to wake up.

Then I got absolutely lucky and I found the existence of this command (shortened for clarity):

H8314:/ $ dumpsys meminfo
Applications Memory Usage (in Kilobytes):
Uptime: 308163299 Realtime: 757582697

Total PSS by process:
1,111,082K: com.android.systemui (pid 1861 / activities)
267,309K: com.android.settings (pid 8980 / activities)
257,282K: system (pid 1385)
164,388K: vendor.somc.hardware.camera.provider@1.0-service (pid 12632)
102,131K: com.sonymobile.home (pid 3493 / activities)

Total PSS by OOM adjustment:
527,841K: Native
blablabla

1,527,421K: Persistent
1,111,082K: com.android.systemui (pid 1861 / activities)
257,282K: system (pid 1385)

This is not normal (and once I managed to open the Memory stats menu and I switched to sorting by max use, I could also finally cross-check on the device that the thing had indeed peaked at 1.1GB for some reason).

It stands to reason that with "Android OS" always constantly using just north of 1GB of ram (1.5-1.6GB when camera stuff is triggered), if just the freaking User Interface takes another full gig, after you also take away whatever little safety margin memory management reserves for itself you are basically left

at best

with 1100MB. That is, 1100MB that have to suffice for everything you run on the phone (from GMS, to the keyboard, to every app background service and driver daemon).

Swapping can certainly ameliorate that (possibly almost as if you had another real half gigabyte or something like that), but if you are left with less than 2% of disk space that's a death sentence worse than the most zealous OOM killers.

And so at the end of the day, ultimately the question is: why in the hell does system UI go so much awry? That I don't know. Even though as a matter of fact I had so many notifications piled up that it seemed a phonebook, and after I cleared them all everything seemed so much fluid.

But one data point doesn't make a statistics, so I'd wait before claiming anything.

Some hundreds megs can indeed be shaved off this way, but take note the *only* way to actually kill and fix the process altogether is using the am crash com.android.systemui command from adb shell (the force stop button in the Apps menu seems to do something, but pid and memory footprint don't budge).

p.s. my really educate guess is that DP4 hadn't solved anything, it's just that in quite literally less than a day since its release (and installation, thus rebooting) the memory leak still couldn't have piled up yet.

p.p.s. for the longest time before this last "stretch of analysis" I also had the problem of the phone slowing down a lot of the times night light activated: turns out that Xperia good night actions are worded like trash, and "optimise my battery" isn't about the qnovo battery care function but it just turned on stamina mode (without somehow providing any acknowledgment of the fact in either the status bar or the shortcuts panel)