Re: [go-nuts] Go for chess programming

642 views
Skip to first unread message

minux

unread,
Dec 18, 2012, 8:47:46 AM12/18/12
to nguoituyet, golan...@googlegroups.com

On Tue, Dec 18, 2012 at 8:39 PM, nguoituyet <hieu....@gmail.com> wrote:
I have been looking for a language different from C/C++ to write a top chess program for many years. Now I really want to give GO a try. I know that at the current state, GO is not very optimized in terms of performance. My question is that:

Is there any fundamental limitation in GO which prevents it from being a good alternative to C/C++ for chess programming no matters how optimized the library can be?
I don't know any fundamental limitation of Go which prevents performant code from written.

You just need to limit the garbage generated by your program and use 64-bit Go.

Devon H. O'Dell

unread,
Dec 18, 2012, 8:57:26 AM12/18/12
to nguoituyet, golan...@googlegroups.com
2012/12/18 nguoituyet <hieu....@gmail.com>:
> Hi,

Hi!

> I have been looking for a language different from C/C++ to write a top chess
> program for many years. Now I really want to give GO a try. I know that at
> the current state, GO is not very optimized in terms of performance. My
> question is that:
>
> Is there any fundamental limitation in GO which prevents it from being a
> good alternative to C/C++ for chess programming no matters how optimized the
> library can be?

I don't think so. In fact, it would seem almost ideal to me: the ease
of writing concurrent programs coupled with support for multithreading
means that you can easily analyze multiple paths in parallel when
finding the best move. I'm sure many would be interested to see what
you come up with!

--dho

> If the answer for that is 'no' then I'm happy to go with GO now with the
> hope of more performance optimization in the future.
>
> Many thanks!
>
> --
>
>

unread,
Dec 18, 2012, 9:04:40 AM12/18/12
to golan...@googlegroups.com
On Tuesday, December 18, 2012 1:39:16 PM UTC+1, nguoituyet wrote:
Hi,

I have been looking for a language different from C/C++ to write a top chess program for many years. Now I really want to give GO a try. I know that at the current state, GO is not very optimized in terms of performance. My question is that:

Is there any fundamental limitation in GO which prevents it from being a good alternative to C/C++ for chess programming no matters how optimized the library can be?

There are some limitations which have to do with the absence of direct/raw memory access in Go programs, such as:

- it is impossible to implement a fast heterogenous memory allocator in Go

- there are no unions, so some direct conversions of binary values from type T to type U are impossible. For example, if T is int32 and U is [4]byte. It is possible to overcome some of these limitations by using package "unsafe" or C functions.

- compressed pointers are impossible in Go. There are also no bit fields in structs.

- some C/C++ implementations have SSE/AVX intrinsics

- Go implementations are using split stacks, so there is an additional overhead of a couple of additional instructions per function call. It is possible to remove much of this overhead in single-threaded code by improving the compiler.

If the answer for that is 'no' then I'm happy to go with GO now with the hope of more performance optimization in the future.

There are cases where highly optimized C/C++ code will be faster than highly optimized Go. The overall difference may be about N*10%, where N is a small natural number.

If about N*10% difference in performance is acceptable, it is a good choice to implement the chess engine in Go.

Filip Zaludek

unread,
Dec 18, 2012, 9:21:03 AM12/18/12
to golan...@googlegroups.com

Are you going brute force approach? Not yet mentioned, go performs boundary checking, which is limiting.

My artifical estimation based on comparison of asm generated from critical code snippets from my not finished gomoku programm,
gcc c version is at least 50% shorter than gccgo, so it can be only about 50% nps.

-fz

John Asmuth

unread,
Dec 18, 2012, 1:06:04 PM12/18/12
to golan...@googlegroups.com
You can turn this off with a compiler flag. Might be "-B".

minux

unread,
Dec 18, 2012, 3:02:55 PM12/18/12
to nguoituyet, golan...@googlegroups.com

On Wed, Dec 19, 2012 at 12:57 AM, nguoituyet <hieu....@gmail.com> wrote:
Yes, for better or worse, the best approach for chess programming is still brute force essential so speed remains a very important factor. I think boundary checking can be a candidate for a large overhead since there are many small computations happening within array in chess programs. Is there any way to disable to boundary checking? I used to program in Pascal and there is an option in Pascal to turn off the boundary checking which improves some programs significantly.
you can use "-gcflags -B" to disable bound checking with the gc toolchain. for example,
go build -gcflags -B some.go
go install -gcflags -B somgPkg

Kyle Lemons

unread,
Dec 18, 2012, 4:18:25 PM12/18/12
to nguoituyet, golang-nuts
The gc toolchain (and, I assume, the the gccgo toolchain which might be better for generating optimized straight-line code) will omit the bounds checking when it knows that you'll be within bounds. At the moment I think this basically only applies to when you use an unmodified index value from a range to index the slice that is being ranged.


On Tue, Dec 18, 2012 at 11:57 AM, nguoituyet <hieu....@gmail.com> wrote:
Yes, for better or worse, the best approach for chess programming is still brute force essential so speed remains a very important factor. I think boundary checking can be a candidate for a large overhead since there are many small computations happening within array in chess programs. Is there any way to disable to boundary checking? I used to program in Pascal and there is an option in Pascal to turn off the boundary checking which improves some programs significantly.

I am hoping for some number like 80-85%nps of what an optimized C chess programs can achieve.

--
 
 

Filip Zaludek

unread,
Dec 18, 2012, 4:34:35 PM12/18/12
to golan...@googlegroups.com, nguoituyet

I am aware of -B in gc toolchain, but what about bounds checks in gccgo as it produces faster code? I can not see flag to turn it off.

My experimental gomoku results:
go1.0.2                8976 knps
go1.0.2    -B          9634 knps
gccgo4.7.2 -O0         3724 knps
gccgo4.7.2 -O1        11839 knps
gccgo4.7.2 -O2        16176 knps
gccgo4.7.2 -O3        17090 knps

-fz

Ian Lance Taylor

unread,
Dec 18, 2012, 5:10:12 PM12/18/12
to Filip Zaludek, golan...@googlegroups.com, nguoituyet
There is currently no flag to disable bounds checking in gccgo.

I'd be happy to take a patch for it.

Ian

Shivakumar GN

unread,
Dec 19, 2012, 9:04:12 AM12/19/12
to golan...@googlegroups.com
On Tue, Dec 18, 2012 at 6:09 PM, nguoituyet <hieu....@gmail.com> wrote:
Hi,
I have been looking for a language different from C/C++ to write a top chess program for many years. Now I really want to give GO a try.


You may find this chess program a good starting point to improve with a good engine:

hs

unread,
Jan 19, 2013, 10:24:03 AM1/19/13
to golang-nuts
I have written a chess program in Go:

http://code.google.com/p/gochess/

I can't tell how it competes to other engines in term of speed, as
this is not easy to measure (no, perft is not appropriate for
comparing speed). Gochess is probably slow.

I wrote a bunch of benchmarks, maybe you get an idea by running them.
DIsabling boundery checking gives a remarkable speed up.

Regards,

Heiko
Reply all
Reply to author
Forward
0 new messages