[haiku-appserver] Re: [Haiku-commits] r14599 - haiku/trunk/src/servers/app

  • From: Adi Oanca <adioanca@xxxxxxxxx>
  • To: haiku-appserver@xxxxxxxxxxxxx
  • Date: Tue, 01 Nov 2005 20:23:30 +0200

Hi Axel,

Axel Dörfler wrote:
Which is... almost never. :-)

Exactly, for example when an allocation fails. I don't think that exceptions have a big overhead, especially as long as you don't use them :-)

Then why did you? :-)

Umm... I don't think so. At least my tests and the books I read point this as a very simple method of optimizing code.
(readability is down with 5% - not even noticeable)
(the stack footprint ain't bigger at all. one variable put on stack once VS. the same variable pushed an pop-ed many times)

The stack footprint is definitely lowered when you declare variables locally.
Just imagine the following case:
go_work(); // called with a small stack frame
for (...) {
char name[256];
go_work(); // called with a much larger stack frame
}

Note that name _will_ be used inside 'for'.

Inside for, how many times the stack pointer is modified? 2 times, every iteration, isn't it?
Also, how many times name contents is initialized with '\0'? Once every iteration.
The stack footprint will remain bigger, yes, but for methods inside 'for' it's the same for both cases - that's what I meant.
-----
char name[256];
for (...) {
//stack size is x+256
go_work(name);
}
----
for (...) {
char name[256];
//stack size is x+256
go_work(name);
}
You probably just mean:
        char a[16];
        go_work();

        char b[16];
        go_work();

Nope. I don't even understand what you're trying to say.

OTOH I can't imagine how pulling variables out of the local context can increase speed, even if only a few cycles -- especially if GCC is as lazy as you say and doesn't lower the stack footprint when it could.

Have the explanation above.

Also, this code:
>>>+ while (fDesktops.CountItems() > 0) {
>>>+ Desktop *desktop = fDesktops.RemoveItemAt(0);
is not optimal at all.
I'm not saying we should optimize at this stage, but you know, you were the one who said that simple optimizations should find their way at the time the code is written.

True, but there will never be a lot of Desktops around. For everything in the league "less than 100" it probably doesn't matter a lot, anyway. That's usually not where I would start optimizing.

Agree. But do that in 100 places and it begins to matter.


bye, Adi.

Other related posts: