Open samuelchassot opened 2 weeks ago
Looks like the first thing to do is storing hashes. Copying and testing the post from stackoverflow, this works. We should perhaps keep bytes; strings are only for human inspection.
import java.security.MessageDigest
import java.util.HexFormat
object Test:
val bytes = MessageDigest.getInstance("SHA-256")
.digest("any string".getBytes("UTF-8"))
@main
def sha256: Unit =
val s = HexFormat.of().formatHex(bytes)
println(s)
// 1e57a452a094728c291bc42bf2bc7eb8d9fd8844d1369da2bf728588b46c4e75
// same as output of:
// echo -n "any string" | openssl dgst -sha256
Someone could also write a dedicated hash table for storing fixed-length caches in a bytearray or long array. It should be notably faster than Hashmap, as we only need one bytearray to store hashes, and use the ending of the hash multiplied by some costant (by 32 if we have byte array) to index into this array.
Here are some ideas to improve the Stainless cache implementation to improve its performance and reduce its footprint: