0

In my .NET MAUI App I was using an await Task.Run(() => ...); to do a Branch and Bound Calculation. Within that there is also an Task.Run(() => ...);.

So far it was running good, but not fast enough for what I was used to. Then I started to optimize my calculations. The Tests for my calculations are running in a separate csproj and are executed within Milliseconds, now. So I am happy with that.

To optimize the Algorithm I used a Parallel.Ivoke(...) with 2 Threads to do a parallel calculation.

But now, back on my .NET MAUI App on Android Emulator - Pixel 5 API 33 it is very slow. I don't get it how this could happen since my Tests are 127 times faster now.

Is it possible that on the Android Emulator - Pixel 5 API 33 I can't use parallelization and the Parallel.Invoke(...) and Task.Run(...) are not possible?

============ Running App without Debugger ===============

enter image description here

OXO
  • 391
  • 1
  • 8
  • Have you tested on a device or different emulators? Have you debugged your code? – Jason Jun 18 '23 at 14:42
  • Haven’t tested on a real Android device, as I don’t have one, unfortunately. I wanted to debug, but Visual Studio doesn’t stop on my breakpoints within the Task. Don’t know if this is normal (Hot Reload doesn’t work all the time) or if this is a sign it doesn’t work well with parallel code? – OXO Jun 18 '23 at 18:16
  • If the debugger is attached, JIT optimization is disabled. You can use a Debug build; just do `Run without debugger`. Or after downloading, stop debugger, launch app from emulator's home screen. – ToolmakerSteve Jun 18 '23 at 20:20
  • It is very strange: my calculations for this example run within 2 Milliseconds, when executed in my tests. On the Emulator it currently takes 20 Seconds!! I don't get it why it could take so long – OXO Jun 19 '23 at 05:33
  • @ToolmakerSteve - Is it to see how it runs without attaching it to VS and Hot Reload? Seems to be the same. Maybe too many Threads for what the real hardware can handle and therefore switching threads Leads too less efficient execution? There are many Calculations in total. Seems to be better on a PC or Notebook, but from 2 ms to Seconds is strange to me – OXO Jun 19 '23 at 10:41
  • Strange - calculations should be much faster without attached debugger. You really need access to a device + Release build + no debugger attached, to know whether this will work in practice. Explain “2ms” - is that on emulator without parallelism? Or that is directly on pc? If its pc, what is emulator timing without Parallelism? Use a single Task.Run, but NOT Parallel.Invoke. Very different cpu characteristics when native on pc, vs mobile chip, which is what the emulator emulates. Pcs are much better at calculations. – ToolmakerSteve Jun 19 '23 at 13:16
  • I have a C# project for my tests and when I execute these on PC (no emulator involved) they run in 2ms. Running without Debugger is not working out. The App starts then, but I can't see my the UI of my main Screen, just the round moving circle as in the posted picture above. Later, I will let you know how it worked out without Parallelization... – OXO Jun 19 '23 at 14:31
  • @ToolmakerSteve - I could get it running as Release by disabling *"AOT (Enable Ahead-of-Time (AOT) compilation)"* for Release. – OXO Jun 20 '23 at 07:20
  • @ToolmakerSteve - Regarding execution times with Parallel.Invoke and without, it appears to me it does not have a real impact. I have 2 scenarios with a Branch-and-Bound with BestBoundNodeSelection and one with RandomizedNodeSelection. The BestBound obviously produced about 10.000 Nodes to calculate whereas the Randomized only produced 2.800 Nodes to calculate. On my PC they are not far away from each other regarding execution times, whereas in Emulator they really are. On PC, I have 12th Gen Intel(R) Core(TM) i5-1235U 1.30 GHz, 16,0 GB, 64 Bit Windows 11. Is it really so much faster? – OXO Jun 20 '23 at 07:23
  • Just thinking, but do you how it could be possible to calculate the Branch-and-Bound Calculations on the GPU instead of the CPU to reach an performance increase? – OXO Jun 20 '23 at 10:35

0 Answers0