Skip to content

Port to zig 0.14.1#39

Open
JonathanHallstrom wants to merge 4 commits intoSnowballSH:masterfrom
JonathanHallstrom:modernize
Open

Port to zig 0.14.1#39
JonathanHallstrom wants to merge 4 commits intoSnowballSH:masterfrom
JonathanHallstrom:modernize

Conversation

@JonathanHallstrom
Copy link
Copy Markdown

Modernized the entire codebase including build.zig and Makefile, engine is now a little faster due the more modern compiler.

@JonathanHallstrom
Copy link
Copy Markdown
Author

Theres also two small changes, i removed the arena allocator and instead use the c allocator directly in the UCI code so the lines are now properly freed. I also changed the stack size for the search thread to 256MB as the previous limit of 64MB was causing crashes when built with the latest compiler.

@SnowballSH
Copy link
Copy Markdown
Owner

Hey, thanks again for the effort. I tried compiling with your makefile using zig 0.14.1. I am seeing identical outputs as the old version (great!), but the new one is quite a lot slower. I'm not sure what I am doing wrong so I am attaching what I did. Is this what you used to compile?

snowballsh@SnowballSH:~/code/Avalanche$ zig version
0.14.1
snowballsh@SnowballSH:~/code/Avalanche$ make
zig build --release=fast -Dtarget-name="Avalanche"
snowballsh@SnowballSH:~/code/Avalanche$ ./zig-out/bin/Avalanche 
Avalanche Compiled at 2025-06-16-04:04 by Yinuo Huang (SnowballSH)
go depth 10
info depth 1 seldepth 1 nodes 24 time 14 score cp 37 pv d2d4
info string thread 0 nodes 83
info depth 2 seldepth 2 nodes 83 time 56 score cp 29 pv d2d4 g8f6
info string thread 0 nodes 184
info depth 3 seldepth 3 nodes 184 time 93 score cp 35 pv d2d4 g8f6 g1f3
info string thread 0 nodes 363
info depth 4 seldepth 4 nodes 363 time 153 score cp 29 pv d2d4 g8f6 g1f3 d7d5
info string thread 0 nodes 1819
info depth 5 seldepth 7 nodes 1819 time 693 score cp 35 pv e2e4 e7e5 d2d4 e5d4
info string thread 0 nodes 3740
info depth 6 seldepth 7 nodes 3740 time 1376 score cp 26 pv d2d4 d7d5 g1f3 g8f6 c1f4 c8f5
info string thread 0 nodes 4419
info depth 7 seldepth 7 nodes 4419 time 1627 score cp 26 pv d2d4 d7d5 g1f3 g8f6 c1f4 c8f5
info string thread 0 nodes 10924
info depth 8 seldepth 11 nodes 10924 time 4687 score cp 34 pv d2d4 d7d5 g1f3 g8f6 c1f4 c8f5
info string thread 0 nodes 21382
info depth 9 seldepth 12 nodes 21382 time 9334 score cp 39 pv e2e4 e7e5 g1f3 b8c6 d2d4 e5d4 f3d4 g8f6 d4c6 b7c6
info string thread 0 nodes 36029
info depth 10 seldepth 15 nodes 36029 time 18745 score cp 35 pv e2e4 e7e5 g1f3 b8c6 d2d4 e5d4 f3d4 g8f6 d4c6 b7c6 b1c3 f8c5
bestmove e2e4

For comparison, the old binary outputs

info depth 10 seldepth 15 nodes 36029 time 25 score cp 35 pv e2e4 e7e5 g1f3 b8c6 d2d4 e5d4 f3d4 g8f6 d4c6 b7c6 b1c3 f8c5

so the new binary seems 750x slower. Am I missing something?

Thanks.

@JonathanHallstrom
Copy link
Copy Markdown
Author

thats very strange, ill investigate it

@JonathanHallstrom
Copy link
Copy Markdown
Author

yeah its a performance regression where some array copies are no longer elided, the workaround is to take a reference to arrays before accessing them, im applying the changes through the codebase

@JonathanHallstrom
Copy link
Copy Markdown
Author

im working on getting the speed back up now

@JonathanHallstrom
Copy link
Copy Markdown
Author

JonathanHallstrom commented Jun 16, 2025

its unfortunately still not there, almost 2x slower still
edit: i dont know why its still slower:( not sure how it was faster before
edit2: well its probably more copy elision regressions, i think making maybe making a lot of params noalias pointers will help

@SnowballSH
Copy link
Copy Markdown
Owner

Thanks. I see, so the issue is that most of the functions use copy instead of pointers? That sounds plausible. I remember having everything pointers a long time ago but copies turned out to be faster... Perhaps the new compiler does things differently. I can trying making more params pointers some time.

@SnowballSH
Copy link
Copy Markdown
Owner

I can confirm that after your fixes the engine is now much much faster, only 2x slower than the old compiler as you mentioned.

@JonathanHallstrom
Copy link
Copy Markdown
Author

Yeah, the biggest issue was the entire rook and bishop attack arrays being copied for every single call to get the magics.

@JonathanHallstrom
Copy link
Copy Markdown
Author

JonathanHallstrom commented Jan 12, 2026

in dev zig this copying issue seems to be fixed!
0.16.0 should be a good one

@SnowballSH
Copy link
Copy Markdown
Owner

in dev zig this copying issue seems to be fixed!
0.16.0 should be a good one

Thanks a lot for letting me know! I will try it out when possible.

@chrollorifat
Copy link
Copy Markdown

in dev zig this copying issue seems to be fixed!
0.16.0 should be a good one

Thanks a lot for letting me know! I will try it out when possible.

let's go. I thought the project is almost dead. I am so glad to see the crew is still active. let's start working on the engine again with our beloved zig. Btw, are we going to see some android and other packages in the next release?

@JonathanHallstrom
Copy link
Copy Markdown
Author

maybe not exactly what youre looking for, but pawnocchio does have some android compatible builds (aarch64-linux)

@SnowballSH
Copy link
Copy Markdown
Owner

in dev zig this copying issue seems to be fixed!
0.16.0 should be a good one

Thanks a lot for letting me know! I will try it out when possible.

let's go. I thought the project is almost dead. I am so glad to see the crew is still active. let's start working on the engine again with our beloved zig. Btw, are we going to see some android and other packages in the next release?

You might consider this project "dead" in the sense that I don't plan to improve its strength significantly in the near future. As it has been pointed out, you might want to check out pawnocchio, which is stronger and more active.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants