fabulous-dev / Fabulous

Declarative UI framework for cross-platform mobile & desktop apps, using MVU and F# functional programming
https://fabulous.dev
Apache License 2.0
1.13k stars 122 forks source link

Inline small scalars (up to 8 bytes) into ScalarAttribute instance #920

Closed twop closed 2 years ago

twop commented 2 years ago

Detailed description and benchmark results are coming.

here is a preview

Method depth boxed Mean Error StdDev Gen 0 Gen 1 Gen 2 Allocated
ProcessIncrements 15 False 1.162 s 0.0139 s 0.0123 s 113000.0000 38000.0000 7000.0000 413 MB
ProcessIncrements 15 True 1.464 s 0.0069 s 0.0058 s 178000.0000 48000.0000 15000.0000 611 MB
twop commented 2 years ago

After the latest changes the "old" benchmarks for rapid updates has way better numbers:

Before

Method depth Mean Error StdDev Gen 0 Gen 1 Gen 2 Allocated
ProcessMessages 10 163.6 ms 3.19 ms 4.47 ms 24000.0000 6333.3333 1000.0000 75 MB
ProcessMessages 15 2,639.5 ms 34.69 ms 30.75 ms 300000.0000 120000.0000 51000.0000 829 MB

After

Method depth Mean Error StdDev Gen 0 Gen 1 Gen 2 Allocated
ProcessMessages 10 150.0 ms 0.77 ms 0.72 ms 22750.0000 6000.0000 1000.0000 75 MB
ProcessMessages 15 2,495.9 ms 24.08 ms 22.53 ms 295000.0000 116000.0000 47000.0000 832 MB

What changed

Note that there is no difference In memory consumption but the access to update and compare functions and the functions themselves are more efficient. In my guesstimate it went from somewhere 5-7 dynamic dispatches per attribute comparison to about 2-3

Update

found one more improvement

Method depth Mean Error StdDev Gen 0 Gen 1 Gen 2 Allocated
ProcessMessages 10 148.7 ms 0.79 ms 0.73 ms 24500.0000 5750.0000 1000.0000 75 MB
ProcessMessages 15 2,489.2 ms 21.22 ms 19.85 ms 292000.0000 114000.0000 48000.0000 832 MB
twop commented 2 years ago

Also I optimized diffing of attributes so much that it is almost indistinguishable from small scalars

Method depth boxed Mean Error StdDev Gen 0 Gen 1 Gen 2 Allocated
ProcessIncrements 15 False 1.202 s 0.0102 s 0.0090 s 118000.0000 37000.0000 8000.0000 413 MB
ProcessIncrements 15 True 1.263 s 0.0074 s 0.0069 s 119000.0000 42000.0000 8000.0000 479 MB

BUT, it does consume significantly less memory which is probably going to be way more important for mobile devices

TimLariviere commented 2 years ago

@twop Do you think you'll have some time soon to complete this PR, or should I fix the failing build and merge it?

twop commented 2 years ago

I think I will have time this week.

SO we can do two things:

  1. merge and then I convert XF attributes as a separate PR as a follow-up
  2. I will take a stub at converting attributes as a part of this PR this week.

@TimLariviere what are your thoughts?

TimLariviere commented 2 years ago

@twop Good with me :) I'll fix the build and merge then