[bind10-dev] Exception speed
Shane Kerr
shane at isc.org
Wed Oct 14 11:39:44 UTC 2009
Michael,
On Thu, 2009-10-08 at 15:08 -0500, Michael Graff wrote:
> I've checked this into experiments/graff-exceptions. It's a quick hack,
> but sort of interesting in that an exception seems to be approximately
> 300x slower than a non-exception path.
>
> I believe this means, to me anyway, that we raise exceptions only when
> they really are exceptions, and not just when we can't do something.
> That is, suppose we had a "read this file, and if it exists, parse it."
> We could code this to attempt to open a file, and if it's not there,
> raise a FileNotFound() exception, otherwise process it (which might
> raise a ParseError() exception.) While we won't call that sort of
> things rapidly, perhaps it is best to return something indicating that
> no file was read, and leave the ParseError() there if there is an actual
> parse error.
It's hard to argue with a 300x slowdown. :)
However note that exceptions in the context of slow processing - like
file operations or network I/O - are probably irrelevant.
Also note that unless we are in a performance critical section of code,
making the code easy to read and reliable is *way* more important than
making it fast.
So, I would agree that certainly for things like list processing we
should not use exceptions (meaning we should not throw an exception when
the list is done as a normal course). But for things like the file
processing example you gave, I would say in general we *do* want to use
exceptions. If performance is a problem, we can write a non-exception
method and refactor accordingly.
--
Shane
More information about the bind10-dev
mailing list