flat assembler
Message board for the users of flat assembler.

Index > Projects and Ideas > Sparky8 - The system response improver

Goto page 1, 2, 3  Next
Author
Thread Post new topic Reply to topic
ds316



Joined: 01 Jan 2007
Posts: 7
ds316 22 Jan 2007, 07:51
Hi all,

A few days ago I got fed up with Vista RC1 lagging on my 512 MB machine. So I thought maybe I could force windows into behaving as I thought it should. So, I wrote Sparky8. It's a very very small win32/win64 app that runs itself with Realtime priorities and monitors what application you are using and boosts its priority to high, and when you switch away from that application, its priority goes back to normal.

My friends Core 2 Duo E6600 OC'ed to 3.2 GHz with 2 GB of RAM even saw an immediate improvement in system responsiveness.

Sparky8 is available in both a 32-bit and 64-bit version, although a 32-bit version will work perfectly fine on 64-bit version of windows (ie can still boost priority of x64-based apps). On Windows Vista RC1 x64 with 1 GB of RAM (I upgraded) it uses only 300-400 K of system memory and after 10 hours it hadn't even consumed one second of CPU time.

Seriously recommended, written of course in FASM, source code included in the download:

http://www.virtual-nation.net/node/6

Any comments, recommendations would be nice.

Note: Don't comment on the efficiency of my code too much, and I know there is a not entirely necessary line of code where Sparky8 will constantly check its priority to see if it is still realtime. This is because when Windows starts up apps it forces them to run with a below normal priority, until windows has finished booting then it gets its normal priority. Using the code the way I have just keeps it running at realtime even then, and it running at realtime is actually very important to the way it operates.
Post 22 Jan 2007, 07:51
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 22 Jan 2007, 08:43
just wondering: how exactly do you perform "monitors what application you are using"? topmost window, running time, or what?

nice idea, by the way
Post 22 Jan 2007, 08:43
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3175
Location: Denmark
f0dder 22 Jan 2007, 10:16
Nice idea? Not on a single-core system. If the foreground app enters a compute-intensive eternal loop, you're screwed.

And you're telling me that Vista sucks so much you need hacks like this? Christ, it's even worse than I though, then >_<

PS: Windows already gives the foreground app a (smallish) boost. And I don't mean to dis your work, I just think it's sad if it's necessary for Vista, and a bad idea for single-core machines.
Post 22 Jan 2007, 10:16
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 22 Jan 2007, 12:04
Quote:
If the foreground app enters a compute-intensive eternal loop, you're screwed.
do you think that in such case increasing priority to high has some noticeable effect? you just have to wait a minute for task manager to load anyway..
Post 22 Jan 2007, 12:04
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3175
Location: Denmark
f0dder 22 Jan 2007, 15:15
Hm, I read it as realtime...

but 'high' can be bad enough Smile
Post 22 Jan 2007, 15:15
View user's profile Send private message Visit poster's website Reply with quote
Raedwulf



Joined: 13 Jul 2005
Posts: 375
Location: United Kingdom
Raedwulf 22 Jan 2007, 20:03
i await reactos to enter usable state Smile
Post 22 Jan 2007, 20:03
View user's profile Send private message MSN Messenger Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 22 Jan 2007, 21:49
Sounds great! but ...

deathshrimp316 wrote:

Download:
Attached to this post. You must login to download it.


I seriously have created user accounts at way too many websites. It's annoying to have to remember all those usernames and passwords. Sad

P.S. f0dder, Laughing
Post 22 Jan 2007, 21:49
View user's profile Send private message Visit poster's website Reply with quote
ds316



Joined: 01 Jan 2007
Posts: 7
ds316 27 Jan 2007, 09:46
Ah, forgot I made users login.

I suppose for the good folks here I can attach it to my post. Very Happy

As for 'bad-idea on single-core systems', I had it running prime95 at a high priority (apps are boosted to high-priority) and it was still very responsive. I even ran my own program which just goes

label:
some random instructions
jmp label

once it has loaded. And there was no change in responsiveness. If however, I went to realtime then yes I do understand your concern as I have a few benchmarking programs I've written that run at realtime and while they are running the computer is 100% unusable. Sparky8 itself does however run at realtime.

It uses GetForegroundWindow and GetWindowThreadProcessId in user32.dll to determine the process that is in the foreground.

I'm running a single-core celeron 3.06 GHz and I've never had trouble with apps actually slowing down the system while sparky8 is running.

The boost that windows gives by default is negligible and might as well not be there, can still take seconds for Windows to redraw the window contents if you've got things running in the background. A simple way to test its effectiveness is to encode DVD, compress files and any other CPU intensive tasks you can think of then try opening apps and switching windows - without sparky8 this can become annoying and slow, but with sparky8 it only takes a maximum of 50 ms for the app to have higher priority than everything else.

As for Vista being shit, I am running RC1, and the responsiveness is fairly on par with XP, just a little lower when both have 512 MB. With 1 GB they are pretty much the same, but both can still be boosted with Sparky8. The Core 2 Duo that still was boosted with sparky8 was running XP Pro, as sparky8 boosts XP just as well as Vista. And I would assume that it boosts 95/98/Me/NT as it should in theory work on those, but it has not at all been tested on those OS's


Last edited by ds316 on 31 May 2007, 11:50; edited 1 time in total
Post 27 Jan 2007, 09:46
View user's profile Send private message Reply with quote
ds316



Joined: 01 Jan 2007
Posts: 7
ds316 31 Jan 2007, 10:14
I'll be doing some more development on this in the next couple of days, most importantly adding in the feature that will prevent 2 copies of Sparky8 running at the same time.

Of course, don't forget to post your own results of how Sparky8 is performing on your computer. I would ask that everyone who downloads this posts a comment if possible, as the more feedback I get the more I can improve this.
Post 31 Jan 2007, 10:14
View user's profile Send private message Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 13 Mar 2007, 10:59
ds316, I haven't run it much lately because (believe it or not) I haven't been able to perceive much of an improvement. Is there an easy way to find out how much time I'm supposedly saving?? Confused
Post 13 Mar 2007, 10:59
View user's profile Send private message Visit poster's website Reply with quote
white_wight



Joined: 03 Feb 2006
Posts: 24
white_wight 13 Mar 2007, 16:47
ds316 wrote:

I'll be doing some more development on this in the next couple of days, most importantly adding in the feature that will prevent 2 copies of Sparky8 running at the same time.


Somewhere in your data section
Code:
_mutex_name db 'Sparky8 is already here',0
    

At the beginning of your code section goes
Code:
invoke  CreateMutex,NULL,FALSE,_mutex_name
invoke  GetLastError
cmp     ax,ERROR_ALREADY_EXISTS
je      exit
    


P.S. for x86
Post 13 Mar 2007, 16:47
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 13 Mar 2007, 17:13
white_wight:
you should check for error this way:
Code:
invoke  CreateMutex,NULL,FALSE,_mutex_name 
test eax, eax
jne okay
invoke  GetLastError 
cmp     eax,ERROR_ALREADY_EXISTS 
je      exit
jmp other_error
okay:    

because:

1. CreateMutex is not quaranteed to change value of last error to 0, when it succeeds. Remember GetLastError gets last error that happened, not last return status.

2. CreateMutex can fail for other reasons than ERROR_ALREADY_EXISTS, you should always think of this
Post 13 Mar 2007, 17:13
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 13 Mar 2007, 17:18
CreateMutex documentation wrote:
Return Values

If the function succeeds, the return value is a handle to the mutex object. If the named mutex object existed before the function call, the GetLastError function returns ERROR_ALREADY_EXISTS. Otherwise, GetLastError returns zero.
If the function fails, the return value is NULL. To get extended error information, call GetLastError.


Better use
Code:
invoke  CreateMutex,NULL,FALSE,_mutex_name 
invoke  GetLastError 
test    eax, eax 
jnz     exit     


That way you handle ERROR_ALREADY_EXISTS and unexpected errors at the same time.
Post 13 Mar 2007, 17:18
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 13 Mar 2007, 17:35
Loco: read it again and carefully. Razz
Post 13 Mar 2007, 17:35
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
white_wight



Joined: 03 Feb 2006
Posts: 24
white_wight 13 Mar 2007, 18:23
vid wrote:

2. CreateMutex can fail for other reasons than ERROR_ALREADY_EXISTS, you should always think of this

Example maybe? Smile
You see, vid, in this particular case there is made a check for a specific error and i don't care why CreateMutex may fail and if it fails at all (i care only of this specific error); and the mutex is used (again, in this particular case Wink ) to make the application be run one-instance, and only.
So if you know how other error check(s) would be useful here, i'm all ears Wink


LocoDelAssembly: as vid mentioned already, be sometimes paciente not only loco Wink
Post 13 Mar 2007, 18:23
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 13 Mar 2007, 21:24
Quote:
Quote:
CreateMutex can fail for other reasons than ERROR_ALREADY_EXISTS, you should always think of this
Example maybe?

In WinAPI everything can fail unless MSDN states otherwise (and even then sometimes...)

If you want example, just think about it a little. CreateMutex for sure has to allocate some bit of memory. Allocation may fail. Another example is directly in MSDN description of function ( http://msdn2.microsoft.com/en-us/library/ms686927.aspx):
Quote:
However, if the caller has limited access rights, the function will fail with ERROR_ACCESS_DENIED and the caller should use the OpenMutex function.


MS even gives you example how to use CreateMutex: http://msdn2.microsoft.com/en-us/library/ms686927.aspx

Quote:
So if you know how other error check(s) would be useful here, i'm all ears
all checks for every possible error state is useful. With WinAPI you have no idea which errors codes can be returned by API call.
Post 13 Mar 2007, 21:24
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3175
Location: Denmark
f0dder 13 Mar 2007, 22:49
List to vid and stop writing crappy code. 'nuff said.
Post 13 Mar 2007, 22:49
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 13 Mar 2007, 23:08
vid, I read it as

Quote:
Return Values

If the function succeeds, the return value is a handle to the mutex object. If the named mutex object existed before the function call, the GetLastError function returns ERROR_ALREADY_EXISTS. Otherwise, GetLastError returns zero.
If the function fails, the return value is NULL. To get extended error information, call GetLastError.


Quote:

On success -> retVal = handle; lastError = {0, ERROR_ALREADY_EXISTS}
On failure -> retVal = NULL; lastError = {1..ERROR_ALREADY_EXISTS-1, ERROR_ALREADY_EXISTS+1..$FFFFFFFF}


And I prefer to handle this way because if the "unexpectable error" occurs I must exit because I failed to check the existence of an existing instance and I don't want to continue because maybe another instance already exists.

Also note that I wrote the post before your post and when I saw my last preview I saw that you posted but I was too lazy to point that out Razz


Last edited by LocoDelAssembly on 14 Mar 2007, 00:05; edited 1 time in total
Post 13 Mar 2007, 23:08
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3175
Location: Denmark
f0dder 13 Mar 2007, 23:20
On my system (XP SP2) CreateMutex does clear lasterror on success, but I don't see this guaranteed in MSDN. Just write proper code, it's not like it's a big fucking deal to do. If you don't care about the particular error, drop the GetLastError call and abort if CreateMutex returns 0.
Post 13 Mar 2007, 23:20
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 13 Mar 2007, 23:59
And where is the backward compatibility??

My quote was extracted from http://win32assembly.online.fr/files/win32api.zip says very explicitly that LastError will be set to 0 on success.

Now programs that trusted on this could become buggy in the future?

PS: I will edit my previous post to make it a little bit more clear.
Post 13 Mar 2007, 23:59
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2, 3  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.