[J3] [EXTERNAL] Re: Exception handling - Golang proposal

Ondřej Čertík ondrej at certik.us
Wed Jul 24 23:34:59 EDT 2019



On Wed, Jul 24, 2019, at 8:39 PM, Van Snyder via J3 wrote:
> On Wed, 2019-07-24 at 15:44 -0600, Ondřej Čertík via J3 wrote:
> 
> > > If the semantic description of block-structured exception 
> > > handling in the standard for some language inevitably results in
> > > optimization problems, I'd be interested to know what those 
> > > specifications are, rather than vague handwaving....
> 
> > Sure. The C++ paper I posted
> > (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0709r0.pdf),
> > page 8, point (1) discusses details of that. 
> 
> Maybe I didn't read in enough detail, but I didn't see a discussion of
> "This feature of the design of C++ exception handling inevitably causes
> performance and/or optimization problems," or "no matter how a
> block-structured exception handling framework is organized, performance
> and/or optimization problems cannot be avoided."
> 
> The report seems to imply that too much generality in the C++ exception
> framework causes problems.  It seems to say "If you're designing a
> block-structured exception handling mechanism, don't copy the way C++
> specifies it."

Yes, that's why I sent the other two links with some code examples. However, I would like to see some better examples. So I also did this experiment:

Download the Stockfish chess program, compile with and without exceptions and check the benchmarks:

git clone https://github.com/official-stockfish/Stockfish
cd Stockfish/src
make build ARCH=x86-64
./stockfish
bench

Then apply the following patch that removes the -fno-exceptions command line option (so we enable exceptions in g++):


diff --git a/src/Makefile b/src/Makefile
index 285d314e..ee7b212c 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -147,7 +147,7 @@ endif
 
 ### 3.1 Selecting compiler (default = gcc)
 
-CXXFLAGS += -Wall -Wcast-qual -fno-exceptions -std=c++11 $(EXTRACXXFLAGS)
+CXXFLAGS += -Wall -Wcast-qual -std=c++11 $(EXTRACXXFLAGS)
 DEPENDFLAGS += -std=c++11
 LDFLAGS += $(EXTRALDFLAGS)
 

and recompile:

git clean -dfx
make build ARCH=x86-64
./stockfish
bench




The Stockfish benchmarks print:


Total time (ms) : 1645
Nodes searched  : 3357457
Nodes/second    : 2041007



And I tried this with and without exceptions many times, and I couldn't see any differences in the timings (the timings vary, but if I run this 20x times with and without exceptions, the mean, minimum and variance of the timings is the same). So at least in this case, there does not seem to be any overhead if exceptions are enabled. I used Ubuntu 18.04 and g++ 7.4.0. The binary without exceptions is a little bit smaller than the binary with exceptions enabled.

However, it's interesting that by default Stockfish turns the exceptions off in their Makefile. So they must have a reason for that.

I agree with you Van that I would like to see some actual code that slows down. I was hoping Stockfish could do it, but it's an example of a C++ code that does not slow down. If somebody finds some other code that shows the actual slowdown, I would be interested.


Ondrej


More information about the J3 mailing list