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

Improve maximum hash table memory estimation. #10190

Merged
merged 1 commit into from
Dec 6, 2021

Conversation

gcp
Copy link
Contributor

@gcp gcp commented Dec 1, 2021

Some browsers don't report navigator.deviceMemory to keep
fingerprintability to a minimum. Currently, lila assumes that
such a machine provides at most 256MB RAM, thus setting a 32MB
max hashtable limit.

This was a reasonable starting point when Stockfish was pure
JavaScript in a single thread, but with up 16 core WASM support
this limitation is a bit more painful.

Modify the memory estimation: if the browser is modern enough to
have full WASM/SharedArrayBuffer support, and thus run the
parallel WASM versions, assume the machine has at least 2GB of
RAM. If it doesn't, assume 512MB. This gives a maximum hashtable
of 256MB and 64MB, respectively.

The assumed minimum RAM values roughly correspond to Firefox's
official system requirements for the 32-bit and 64-bit version.
Although that doesn't necessarily correspond to WASM support,
it's a reasonable starting point for a guess.

Note that guessing wrong isn't harmful, it just gives the user
the option to shoot themselves in the foot, and even that is
limited because we still only use 1/8th of the guessed system RAM.

Some browsers don't report navigator.deviceMemory to keep
fingerprintability to a minimum. Currently, lila assumes that
such a machine provides at most 256MB RAM, thus setting a 32MB
max hashtable limit.

This was a reasonable starting point when Stockfish was pure
JavaScript in a single thread, but with up 16 core WASM support
this limitation is a bit more painful.

Modify the memory estimation: if the browser is modern enough to
have full WASM/SharedArrayBuffer support, and thus run the
parallel WASM versions, assume the machine has at least 2GB of
RAM. If it doesn't, assume 512MB. This gives a maximum hashtable
of 256MB and 64MB, respectively.

The assumed minimum RAM values roughly correspond to Firefox's
official system requirements for the 32-bit and 64-bit version.
Although that doesn't necessarily correspond to WASM support,
it's a reasonable starting point for a guess.

Note that guessing wrong isn't harmful, it just gives the user
the option to shoot themselves in the foot, and even that is
limited because we still only use 1/8th of the guessed system RAM.
@niklasf
Copy link
Member

niklasf commented Dec 6, 2021

Thanks!

Currently the user experience when trying to use too much memory isn't great (Stockfish will just fail to start without any feedback), but the estimates still seem pretty conservative in any case.

@niklasf niklasf merged commit f5463f8 into lichess-org:master Dec 6, 2021
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

2 participants