[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 01:02:58 +0200

Ingo Weinhold wrote:

On 2005-10-31 at 21:50:20 [+0100], Adi Oanca wrote:

   What if we avoid programming with exceptions and compile the app_server
without exceptions support? This should get us some speed...
Is it possible?

It is possible, though. Whether it really gains a lot is another thing. AFAIK the overhead of using exceptions is not really relevant (if there is overhead at all -- you have to do error checking anyway). Throwing exceptions can be rather expensive, though, which is why one should use them only for really exceptional cases.

Which is... almost never. :-)

+            while (fDesktops.CountItems() > 0) {
+                Desktop *desktop = fDesktops.RemoveItemAt(0);


+ }
- Layer *layer;
- for (int32 i = 0; i < windowCount; ++i)
- // is this layer in fact a WinBorder?
- if ((layer = static_cast<Layer*>(sDesktop->WindowList().ItemAtFast(i)))) {


- }

To avoid a few CPU cycles please pull out local declarations from loops.

Please don't do something like this; keeping variables as local as possible increases the readability. Furthermore trust the compiler. Don't try to trick it -- it's your friend. Extending the scope of a variable may cause a bigger stack footprint and may even make your code slower, since the compiler has less knowledge it can apply.

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)

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.

bye, Adi.

Other related posts: