You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was curious about how you were using rollinghash, so I started reading your code.
For increased speed, I would highly recommend that you cast your rolling hashes to the actual underlying hash used. So at cmd/muscato_screen/main.go:146, I would replace
hashes:=*hashPool.Get().(*[]rollinghash.Hash32)
with
hashes:=*hashPool.Get().(*[]buzhash32.Buzhash32)
Indeed, when you cast to an interface, the compiler does not know which actual implementation you are referring to (because it could be changed at run time). Specifying the actual implementation allows the compiler to inline the calls to Roll(), which should lead to noticeable speed improvements. I mention this in https://github.com/chmduquesne/rollinghash#gotchas, but you are a long time user so you wrote this code before I realized this and documented it.
Another thing you could do is to attempt using buzhash32.GenerateHashes(seed). It is similar to your genTables(), but it is directly provided by buzhash32. So in cmd/muscato_screen/main.go:106, you could replace
One direct benefit is that it would be less code to maintain for you: you could get rid of your tables array and of your genTables function.
A second, indirect benefit, is that buzhash32.GenerateHashes is designed to predictably generate from a seed, so you could take advantage of this in order to always get the same collection of rollinghashes. You would do that by replacing the call to rand.Int63() with a call to myrand.Int63(), where myrand is a rand.Rand object initiated with a predictable source. I believe this could serve you when writing tests.
Hi @kshedden ,
I was curious about how you were using rollinghash, so I started reading your code.
For increased speed, I would highly recommend that you cast your rolling hashes to the actual underlying hash used. So at cmd/muscato_screen/main.go:146, I would replace
with
Indeed, when you cast to an interface, the compiler does not know which actual implementation you are referring to (because it could be changed at run time). Specifying the actual implementation allows the compiler to inline the calls to Roll(), which should lead to noticeable speed improvements. I mention this in https://github.com/chmduquesne/rollinghash#gotchas, but you are a long time user so you wrote this code before I realized this and documented it.
Another thing you could do is to attempt using
buzhash32.GenerateHashes(seed)
. It is similar to yourgenTables()
, but it is directly provided bybuzhash32
. So in cmd/muscato_screen/main.go:106, you could replacewith
One direct benefit is that it would be less code to maintain for you: you could get rid of your
tables
array and of yourgenTables
function.A second, indirect benefit, is that
buzhash32.GenerateHashes
is designed to predictably generate from a seed, so you could take advantage of this in order to always get the same collection of rollinghashes. You would do that by replacing the call torand.Int63()
with a call tomyrand.Int63()
, wheremyrand
is arand.Rand
object initiated with a predictable source. I believe this could serve you when writing tests.All the best,
@chmduquesne
Keep in mind that I did not attempt to compile any of this, so there might be mistakes :-)
The text was updated successfully, but these errors were encountered: