Windows slows down FB apps that are working in the background [solved]

General discussion for topics related to the FreeBASIC project or its community.
Post Reply
Provoni
Posts: 513
Joined: Jan 05, 2014 12:33
Location: Belgium

Windows slows down FB apps that are working in the background [solved]

Post by Provoni »

Hey all,

My program works fine when it is focused and in the foreground. But as soon as I do something trivial like opening up Explorer my program slows down to about 1/4 of it's speed. My programs need to run for hours or days at a time and it's unacceptable.

It's a new computer, Windows 11 Home, Intel Alder Lake laptop with the power connecter plugged in. My old PC, which was a workstation class computer with Win 10 Pro did not have this issue.

Switching the priority of my program to the highest setting does not help.

Turning off Game mode didn't fix the issue.

Google does not understand the questions I ask it.

If need be I can provide a video.

Thanks
Last edited by Provoni on Feb 09, 2023 10:55, edited 1 time in total.
SARG
Posts: 1763
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Windows slows down FB apps that are working in the background

Post by SARG »

Hi Provoni

What does Task Manager show (%CPU) when your program is running in fore/back ground ?
What sort of program is it ? If it's full screen and if possible try windowed mode.

For the moment my laptop has not yet been migrated to W11 so I cannot test.
marcov
Posts: 3462
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: Windows slows down FB apps that are working in the background

Post by marcov »

For Desktop versions of Windows, the scheduler favors the focussed application with extra ticks. For server edition, the ticks favor background apps (services, not unfocused gui apps afaik).

This has been the case since I use windows (Win NT 3.5 or so)

So an unpractical solution: turn it into a service, and run a Windows server version. Other options are to look into setting thread priorities. Also make sure your power scheme is set to "always on" .

p.s. any speed from CPU "boosts", i.e. above the base clock are unreliable long term anyway. Benchmarking short whiles with the application focus is not a reliable way of benchmarking
Provoni
Posts: 513
Joined: Jan 05, 2014 12:33
Location: Belgium

Re: Windows slows down FB apps that are working in the background

Post by Provoni »

SARG wrote: Feb 09, 2023 8:22 Hi Provoni

What does Task Manager show (%CPU) when your program is running in fore/back ground ?
What sort of program is it ? If it's full screen and if possible try windowed mode.

For the moment my laptop has not yet been migrated to W11 so I cannot test.
I let the program use 3/4 of the threads. So it runs around 75%, in the background it goes under 20%.

viewtopic.php?p=203927#p203927

Program is running in windowed mode.

It's also other programs of mine, that for example are just single threaded.
Provoni
Posts: 513
Joined: Jan 05, 2014 12:33
Location: Belgium

Re: Windows slows down FB apps that are working in the background

Post by Provoni »

marcov wrote: Feb 09, 2023 8:28 For Desktop versions of Windows, the scheduler favors the focussed application with extra ticks. For server edition, the ticks favor background apps (services, not unfocused gui apps afaik).

This has been the case since I use windows (Win NT 3.5 or so)

So an unpractical solution: turn it into a service, and run a Windows server version. Other options are to look into setting thread priorities. Also make sure your power scheme is set to "always on" .

p.s. any speed from CPU "boosts", i.e. above the base clock are unreliable long term anyway. Benchmarking short whiles with the application focus is not a reliable way of benchmarking
Thread priorities set to highest via the task manager.

CPU boost is not the problem.

I wonder if any 3rd party software is causing it. I'll try some things.
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Windows slows down FB apps that are working in the background

Post by dodicat »

Google used to incorporate the 1 millisecond minimum resolution for sleep 1 in fb.
That is, running fb graphics while online with Google resulted in that minimum sleep time.
Now it doesn't, I am not saying that is a bad thing, but I wish freebasic could give one millisecond when asked for (sleep 1) instead of about 15 milliseconds.
At the moment I am stuck with a maximum framerate of about 64 with sleep 1
If I uncomment settimer and freetimer I get about 445 FPS, this is what Google used to do, java also used to give one millisecond resolution.
Maybe it is because of my cpu, I don't know, it is Intel.

Code: Select all




Declare Function settimer       Alias "timeBeginPeriod"(As Ulong=1) As Long
Declare Function freetimer      Alias "timeEndPeriod"  (As Ulong=1) As Long

Function framecounter() As Integer
      Var t1=Timer,t2=t1
      Static As Double t3,frames,answer
      frames=frames+1
      If (t2-t3)>=1 Then
            t3=t2
            answer=frames
            frames=0
      End If
      Return answer
End Function

Screen 19
Do
      Screenlock
      Cls
      Locate 2,2
      Print "FPS ";framecounter
      Screenunlock
     ' settimer  '<< --------------- uncomment both settimer and freetimer to give 1 millisecond sleep 1
      Sleep 1
      ' freetimer
Loop Until Len(Inkey)


 
Provoni
Posts: 513
Joined: Jan 05, 2014 12:33
Location: Belgium

Re: Windows slows down FB apps that are working in the background

Post by Provoni »

Another observation among the same line:

Compilation time of my program with FbEdit in the foreground: 2:49 mins

Compilation time of my program with Windows Explorer in the foreground: 3:54 mins

My power scheme is always on, all power saving options disabled.
Provoni
Posts: 513
Joined: Jan 05, 2014 12:33
Location: Belgium

Re: Windows slows down FB apps that are working in the background

Post by Provoni »

Resolved:

https://www.isunshare.com/windows-10/2- ... .html#way1

Set Windows to prefer background services. Go figure?
Provoni
Posts: 513
Joined: Jan 05, 2014 12:33
Location: Belgium

Re: Windows slows down FB apps that are working in the background [solved]

Post by Provoni »

My AMD laptop, also with Windows 11, does not aggresively tune down performance of programs in the background. This may be Intel only, and I suspect it may have to do with the efficiency cores of the 12th gen and upwards CPU's (big.Little).
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: Windows slows down FB apps that are working in the background [solved]

Post by caseih »

I'm surprised you saw this behavior on a multi-core system. On a single core I could understand the prioritization scheduling prioritizing the foreground app. but on a multi-core system this would be rather pointless unless all the cores were being utilized. But I guess many things about Windows surprised me.
Provoni
Posts: 513
Joined: Jan 05, 2014 12:33
Location: Belgium

Re: Windows slows down FB apps that are working in the background [solved]

Post by Provoni »

Update: the issue was still happening to some degree.

If I let Windows prio background apps than anything on the foreground could literally freeze. For example, loading an image would just freeze and no image appeared. If the frozen window with the image would be put in the background it would instantly load and show the image (all or nothing).

If I let WIndows prio foreground then exactly the opposite would happen. Again, in an all or nothing kind of way. In both of those cases my laptop would act if it was frozen / stuttering / etc. Seriously annoying and bad for my workflow.

Windows 3.1 on my 386 was more repsonsive.

The issue was entirely fixed by disabling the Intel CPU's E-cores in the bios.

The CPU in question is a Intel Core 12650H Alder lake CPU. It was released over a year ago, you'd think they would fix it by now. Pretty sure that it is Windows not managing the threads well and not a CPU problem.

My other laptop, a 3 year old HP Omen 15 with a AMD Ryzen 4800H made more fan noise than a server (not exaggerated). It just received an update - three years after the facts - through the Omen software where it stated that they fixed a bug where on some laptops the CPU boost was constantly put to aggressive. Now it's actually silent and I can use the laptop in a normal way.

Unbelievable.
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: Windows slows down FB apps that are working in the background [solved]

Post by caseih »

Yeah that's very interesting. Is it just your compiled EXEs that experience the problem or do you think every app experiences a slowdown but most you don't notice?
Provoni
Posts: 513
Joined: Jan 05, 2014 12:33
Location: Belgium

Re: Windows slows down FB apps that are working in the background [solved]

Post by Provoni »

Haven't tested other apps. I suppose it's a general issue, there are lots of YouTube videos about it.
Provoni
Posts: 513
Joined: Jan 05, 2014 12:33
Location: Belgium

Re: Windows slows down FB apps that are working in the background [solved]

Post by Provoni »

Issue resolved without disabling e-cores. It is not FreeBASIC related but it may concern you if you own a 12th gen or higher Intel CPU or anything else that has assymetrical cores etc.

To fix it right click on the Start icon and pick energy/power and in the new window put energy mode to Best performance. For me this setting was controlled by the vendor's software so I had to go into the vendor software and tell it to let Windows handle it.

Setting it to Best performance stops Windows from off-loading anything in the background to the e-cores. It is ridiculous behaviour. Sorry Intel, my next CPU will be AMD. Struggled with this issue for a month.

Found this post: https://foldingforum.org/viewtopic.php?t=38850
TomChaai wrote: This is a problem for certain workflows that some power users may use, for example building/rendering a project, then either write some emails or just browse youtube. The scheduler may decide to put the browser on P cores and put the heavyweight rendering software on E cores, which is counterproductive.
TomChaai wrote: Title says it, on a PC with both P-cores and E-cores, such as 12700K, workload always got scheduled to E-cores, wasting at least 70% of available power.

Setting fold power or core slot has no effect, the only workaround is to set "processor affinity" for the CPU workload process to disable all E-cores of that process. However the process respawns for each new workload, forcing manual intervention every time.

Apparently this issue is only found on Windows 11 22H2, last build did not have this problem.
Post Reply