Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small cleanups 06 #2628

Closed
wants to merge 13 commits into from
Closed

Conversation

vondele
Copy link
Member

@vondele vondele commented Apr 13, 2020

Starting with an empty PR to collect suggestions for small cleanups.

No functional change.

Starting with an empty PR to collect suggestions for small cleanups.

No functional change.
@protonspring
Copy link

@Vizvezdenec
Copy link
Contributor

This is not big, but...
We have all search bools starting from lowercase letters.
cutNode, rootNode, captureOrPromotion, singularLMR, etc.
Only PvNode for some reason starts from capital letter which sometime causes me to white patch in a wrong way, then read compiler message (no CutNode bool, proposing cutNode bool), swear, rewrite...
I guess it will be logical to have all this bools starting from lowercase letters for consistency.

@vondele
Copy link
Member Author

vondele commented Apr 13, 2020

@Vizvezdenec the idea behind is that PvNode is a constexpr.... i.e. known at compile time. cutNode is known only at runtime hence small. Other example are RazorMargin (compile time constant), like most other compile time constants, but we're not 100% consistent e.g. ttHitAverageWindow (should be TtHitAverageWindow).

@Vizvezdenec
Copy link
Contributor

Vizvezdenec commented Apr 13, 2020

I'm just saying that PvNode is the same caliber of bool as rootNode and cutNode - and they are both from lowercase.
They are often used in the same expressions or close to each other. This is kinda inconsistent imho :) Sure it's constexpr or w/e but it's mostly used with not constexpr statements anyway.
After all it's like
If it's [alpha; beta] node it's rootNode for ply 0, PvNode for ply >= 0, if it's > beta it's cutNode, this seems kinda strange from logical point of view :)

@protonspring
Copy link

These are faster on my machines, and, to me, they are easier to read/understand.

master...protonspring:ps_relatives3

@Lolligerhans
Copy link
Contributor

Lolligerhans commented Apr 15, 2020

I have this refactoring of shift<>(bb), removing the excessive repetition of left-/right shifts, directions and masking. I did not test the changes because the executable is identical on my setup.
https://github.com/official-stockfish/Stockfish/compare/master...Lolligerhans:shift?expand=1

E: link on top of this branch https://github.com/vondele/Stockfish/compare/smallCleanups06...Lolligerhans:shift?expand=1

If the change is welcomed I can add comments or change formatting.

@Lolligerhans
Copy link
Contributor

@protonspring
Copy link

protonspring commented Apr 16, 2020

For pos.castling_rights(Color c), we can use the correct operator in types.h.

master...protonspring:ps_castlingrights11

@protonspring
Copy link

protonspring commented Apr 16, 2020

We don't need to ~pos.checkers() every time. This is a little faster:

master...protonspring:ps_sliderattacks3

master nps: 1606695, patch nps: 1634694

@mstembera
Copy link
Contributor

mstembera commented Apr 17, 2020

@protonspring I originally thought having the ~pos.checkers() outside of the loop would be more efficient as well but as @Rocky640 pointed out here(and I verified)
#2584 (comment)
the loop gets executed less than once per call on average. Therefore having it inside the loop is actually better. (I could not measure any speed difference either way.)

@Lolligerhans
Copy link
Contributor

Personally, I had an easier time if there were bakward_* version of forward_ranks_bb and -_file_bb. I can create a diff if required.

@sb362
Copy link

sb362 commented Apr 17, 2020

There's an unnecessary square_bb() in Position::set_castling_right() which can be removed
sb362@28a8abe

@silversolver1
Copy link

Some very minor typos in comments in tbprobe.cpp: master...silversolver1:tbprobe_typos_1

@@ -412,11 +412,11 @@ constexpr Rank rank_of(Square s) {
}

constexpr Square relative_square(Color c, Square s) {
return Square(s ^ (c * 56));
return c == WHITE ? s : flip_rank(s);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and line 419 changes are actually somewhat slower on my machine. It seems that introducing branching is not a good idea.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get bit by this occasionally. Patches test faster on my machine, but others say it's slower. Any ways to counteract that? How are you testing performance?

@mstembera
Copy link
Contributor

mstembera commented Apr 18, 2020

@protonspring I use Fishbench from https://github.com/zardav/FishBench w/ 40 tests which eliminates/reduces variance from run to run and issues with turbo boost because both master and patch run simultaneously. It is known that sometimes different versions may perform slightly differently on different machines so getting others to verify speed differences is a good thing.

@Rocky640
Copy link

@protonspring @mstembera
It would be interesting to know
a) which compiler is used
b) bmi or modern
c) window or linux

@mstembera
Copy link
Contributor

@Rocky640 I used gcc 8.1, bmi2, & windows.

@protonspring
Copy link

@Rocky640 My numbers were on gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0. I don't remember enabling bmi, so it's probably not enabled.

@vondele
Copy link
Member Author

vondele commented Apr 20, 2020

@mstembera @protonspring next to the setup, the measured speedup/slowdown, and the estimated error for that would be useful as well.

@mstembera
Copy link
Contributor

mstembera commented Apr 21, 2020

@vondele

Results for 40 tests for each version:
            Base      Test      Diff      
    Mean    1880457   1861728   18729     
    StDev   42071     32077     58858     

p-value: 0.375
speedup: -0.01

I personally subscribe to the guideline that when in doubt it's best to avoid branching because branches are usually slower and less deterministic in performance(due to branch prediction issues) than normal instructions. Master is also nicely symmetric for white and black.

@linrock
Copy link
Contributor

linrock commented Apr 24, 2020

some ideas:

  • add *.o object files to .gitignore in the repo root so you don't see a big list of untracked files when running git status
  • use a .gitattributes file in the repo root to collapse tuning branch core files in diffs by default to make SPSA run diffs easier to read (see github docs)
  • in source files, remove whitespace between comments and commented functions so that the comments show up as annotations for certain code editors

for example, with intellisense on in VSCode, when hovering over a function that's commented without whitespace between the comment and the function definition, you get a nice annotation.

some functions like attackedBy already don't have that whitespace:

image

but for functions where there's a space between the comment and the function, it's blank when there could be an annotation.

example: pseudo_legal currently has a whitespace between the comment and the definition, so hovering over this shows nothing:

image

when the whitespace is removed, hovering over this shows the comment, which is a lot more useful:

image

@pb00068
Copy link
Contributor

pb00068 commented Apr 25, 2020

@vondele

search.cpp line 837

    improving =  (ss-2)->staticEval == VALUE_NONE ? (ss->staticEval > (ss-4)->staticEval
              || (ss-4)->staticEval == VALUE_NONE) : ss->staticEval > (ss-2)->staticEval;

can now be simplified into

    improving =  (ss-2)->inCheck ? (ss->staticEval > (ss-4)->staticEval
              || (ss-4)->inCheck) : ss->staticEval > (ss-2)->staticEval;

I verified it delivers same bench number (tested with default bench & stockfish.exe bench 16 1 21).
Please let me know if this needs testing on the framework.

@vondele
Copy link
Member Author

vondele commented Apr 25, 2020

@pb00068 no need to test.

@vondele
Copy link
Member Author

vondele commented Apr 28, 2020

@linrock concerning your suggestions.

  • white space between comments and functions... I'm in favor of picking some consistent scheme, right now we mix. If you have a diff I can apply to this branch that would be convenient.
  • .gitignore : not sure we should check in such a file, people might have local variants of the file to ignore files they have usually around (.epd, .out, .xy, etc..) and we don't want to collect those.
  • .gitattributes : to considered to produce cleaner diffs of SPSA runs. However, I think we should merge tune branch in master, it is core functionality.

@Vizvezdenec
Copy link
Contributor

Vizvezdenec commented Apr 29, 2020

Why do we even need this variable?
https://github.com/official-stockfish/Stockfish/blob/master/src/search.cpp#L1027
https://github.com/official-stockfish/Stockfish/blob/master/src/search.h#L35
It's not used anywhere (AFAIK) apart from this part of code, it equals flat 0, it makes no sence from consistency point of view - all other variables in this part of code are just written as flat numbers and not as variables declared in search.h...
ss->staticEval + 235 + 172 * lmrDepth <= alpha
(*contHist[3])[movedPiece][to_sq(move)] < 27400
captureHistory[movedPiece][to_sq(move)][type_of(pos.piece_on(to_sq(move)))] < 0
!pos.see_ge(move, Value(-194) * depth
etc
And all attempts to change this parameter failed in recent years, and even if they didn't - you can change it right there and not dig into search.h to find out that it's indeed 0.

@vondele
Copy link
Member Author

vondele commented Apr 29, 2020

@Vizvezdenec this variable was historically request by zamar #1066 (comment) it makes sense since the same value (minus 1) must be used in Thread::clear otherwise the implementation is incorrect.

@vondele vondele closed this in 353e206 Apr 29, 2020
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.

None yet