TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Blowing up my compile times for dubious benefits

94 pointsby Tyrubiasalmost 2 years ago

9 comments

harerazeralmost 2 years ago
While this post has a good amount of substance, I found it rather hard to understand due to small mistakes (or hidden assumptions, or something else?). All of which seem easily fixed&#x2F;clarified, but these sorts of things are unnecessary friction for readers.<p>Edit: Thanks to Jasper for stating the big hidden assumption made by the author - that he is only considering the case of being blocked by enemy pieces, not one&#x27;s own pieces. This is motivated by the fact that one can use the same side occupancy board to trivially remove all moves that are illegal due to self-blocking. This resolves many of the technical issues, although again, it should be be made explicit. The typos&#x2F;silly errors and pedagogical mistakes remain.<p>Some examples:<p>- According to the first bitboard (and the convention stated in the OP), A2 has index 8, not 1.<p>- In the second bitboard, the rook on e4 should be able to move to e1,a4,e8,h4.<p>- max of 9 relevant occupancy bits for a bishop - how? A bishop on e4 for example would have to check b1,c2,d3,f5,g6,h7 and a8,b7,c6,d5,f3,g2,h1 for a total of 13 bits. Similar mistake for a the rook.<p>- The so called &quot;original&quot; masked occupancy bitboard was not mentioned previously<p>- That same bitboard has variables b1,b2,b3,b4,b5 on it, a notational collision with the squares b1-b5. - The variables b1-b5 are in the wrong place (presumably they were meant to be on c3,d4,e5,f6,g7 since the bishop is on b2, and again there is the question of why not h8 and the other missing squares).<p>- Magic number comes out of nowhere. What is it doing? Presumably the purpose is to extract the relevant positional bits to be the most significant ones while keeping the order, done through the multiplication + bitmasking, but this should be explicitly stated. We also have no idea how it is derived.<p>- What are the &quot;collisions&quot; actually collisions of? It would be nice to see an example of this.
评论 #36432458 未加载
评论 #36427926 未加载
评论 #36427778 未加载
evmaralmost 2 years ago
&gt; to make all the constants known at compile time, everything has to be written in a const function. This means: No allocations [...] No for loops<p>These constants are relatively unchanging relative to the rest of your program. Why not write a code generator (without the above weird restrictions) to compute them once and save the result?
评论 #36432486 未加载
评论 #36430415 未加载
评论 #36427612 未加载
评论 #36431253 未加载
weinzierlalmost 2 years ago
The <i>bitboard</i> approach is similar to how graphics cards used to organize their memory in the heyday. It wasn&#x27;t one big buffer per screen with one or more consecutive bytes representing on pixel and one pixel after another. There were as many buffers as required by the bit depth, e.g. one for black and white, two for 4-colors and so on. Every bit was a pixel, so the top left corner was the MSB of the first byte of any buffer. We called this <i>bitplanes</i>.
liquidisealmost 2 years ago
While i enjoyed the article, the title and opening sentence really deserve credit for being genuinely fun to read.
评论 #36432519 未加载
chaeronanautalmost 2 years ago
An excellent explanation of Magic Bitboards can be found here: <a href="https:&#x2F;&#x2F;analog-hors.github.io&#x2F;site&#x2F;magic-bitboards&#x2F;" rel="nofollow noreferrer">https:&#x2F;&#x2F;analog-hors.github.io&#x2F;site&#x2F;magic-bitboards&#x2F;</a>
carltgalmost 2 years ago
Wow, this is a really cool project. Just one thing that I was curious about... At the end there was talk about elo rating and their uncertainties, but I wasn&#x27;t sure how those were computed and if those were determined to be statistically significant. The dubious benefits of the compile times seem independent from an ELO rating and so I think a statistical test to ensure the significance of the results would be good to further drive the point home.<p>Apart from the ELO claim, the runtime speedup is sure beneficial at the very least! Cheers to the author
the8472almost 2 years ago
I wonder whether using `const` over `static` was intentional here. The first gets instantiated at each use site while the latter exists (approximately) once in the binary.
评论 #36432560 未加载
wyldfirealmost 2 years ago
Mathematical representation of A-bar &#x2F; A&#x27; - this is the complement of the set A? That should probably be `~A` and not `!A` for the bitboard operation. The logical negation would not give you the desired results, instead you want the bitwise negation (`~A`).
评论 #36429524 未加载
littlestymaaralmost 2 years ago
&gt; I suspect that the constant evaluator in Rust is just plain slow.<p>IIRC, it&#x27;s using the <i>miri</i> interpreter, which is indeed very slow.
评论 #36431515 未加载