sorawee
2022-7-2 08:09:13

Could you also update the source in https://pkgd.racket-lang.org/pkgn/package/sudoku-solver to a newer version? Right now it’s pinned at v0.15.1, so the bug is still there.


sschwarzer
2022-7-2 09:29:17

Thanks for the reminder. Done. :slightly_smiling_face:

I had thought I had already done this, but after applying your patch, I had to clean up some CI build issues (unrelated to your patch) and forgot to push the new tag and change it on the package server.


sschwarzer
2022-7-2 09:34:13

Fortunately, the bug was only in the tests. Just to be sure: Did you get any failed tests or even exceptions before the patch? Both here locally and on the package server, the tests passed (even though due to the bug the wrong tests might not have had the intended effect).


sschwarzer
2022-7-2 09:38:22

You can use for with in-vector. The documentation of in-vector says An in-vector application can provide better performance for vector iteration when it appears directly in a for clause.


sschwarzer
2022-7-2 09:40:39

I used a (relatively short) vector instead of a set in another program where the set was also part of the bottleneck. If I remember correctly, I got an additional speedup by using an unsafe vector and unsafe operations (but of course, that’s kinda … unsafe :wink: ). If you use the unsafe variants, you should measure how much the difference is.


sschwarzer
2022-7-2 09:49:45

You can also use <https://docs.racket-lang.org/foreign/homogeneous-vectors.html|more compact vectors>, but I’m not sure if these work with the unsafe ref and set! operations.


sschwarzer
2022-7-2 09:57:57

This works: #lang racket/base (require ffi/vector racket/unsafe/ops) (define a-vector (make-u16vector 5 0)) (for ([i 5]) (u16vector-set! a-vector i i)) (for ([i 5]) (displayln (u16vector-ref a-vector i))) but not with the unsafe operations. You’d need to check whether a regular vector plus unsafe operations or fixed-data (FFI) vectors with their specific safe operations are faster.


sschwarzer
2022-7-2 10:03:02

So if nothing failed or raised an exception, the effect of the bug was only less test coverage than expected, I think.


sschwarzer
2022-7-2 10:37:55

Matthew Butterick has an, I think, interesting article: https://beautifulracket.com/appendix/why-racket-why-lisp.html


sorawee
2022-7-2 15:38:18

I don’t think vector-for-each is even provided in Racket. It’s defined at the Chez Scheme level but not exposed to Racket.

One can use vm-primitive to require it, however, but from a quick test it appears to be slower than for + in-vector.


spdegabrielle
2022-7-2 17:55:37