-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Solve midgames and on locally via bare WebAssembly
The pentago javascript client now solves boards with 18 or more stones locally via bare WebAssembly code running in a WebWorker. Bare WebAssembly means clang-only, without Emscripten. That in turn means no standard library, no malloc, etc. The midengine was already pretty light on memory allocation, so the main hardship was getting a stripped version of libc++ (for type_traits and similar niceties) that works in -ffreestanding mode without malloc and such. I did this by copying the libc++ headers into third_party/freestanding and adding a very large number of ifdefs. A wrinkle: the midengine is memory heavy, and WebAssembly instances can't ever shrink their overall memory size. To get around this, the client makes a fresh WebAssembly instance for each request and throws it away when compile. Thankfully the API separates compilation from instance creation, so this seems fine. Timings for an 18 stone board (https://perfect-pentago.net/#274440791932540184): MacBook Pro, 13-inch, 2019, 2.5 GHz Quad-Core Intel Core i5: Chrome 79 = 12.381 s Firefox 71 = 10.587 s Safari 13.0.4 = 12.572 s iPhone 11 Pro, iOS 13.3: 9.0 s (!) Other improvements along the way: 1. Remove the weird "boards" argument to midengine routines. All available boards are now computed inside the routines. 2. Reduce excessive templatization of midengine to help code size. This results in a small but acceptable 10-15% slowdown. 3. Make midengine work without SSE. 4. Make high_board_t smaller (16 -> 8 bytes) and leaner (no memory allocation). 5. Upgrade server to node 13.5.0. Extensive and painful binding tweaks required. 6. Use fetch instead of XMLHttpRequest in client. Posts which gave me the idea that bare WebAssembly was possible: * https://dassur.ma/things/c-to-webassembly * https://medium.com/@dougschaefer/going-straight-to-clang-for-webassembly-928df1484430
- Loading branch information
Showing
215 changed files
with
138,083 additions
and
422 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.