Hacker Newsnew | past | comments | ask | show | jobs | submit | mdlayher's commentslogin

In this particular case, the compiler can't infer the type of V if you omit the type parameters at the call sites:

  type checking failed for main
  prog.go2:17:3: cannot infer V (prog.go2:46:27)
  prog.go2:22:3: cannot infer V (prog.go2:46:27)
But generally you are right, yes. It is able to infer K at least.


Yep that is true. I wanted both values to be comparable for an easy demo but would write it as you've suggested if I intended to make this a general purpose package.


What I mean is that as written, the demo doesn't need V to be comparable.


Oh wow, for some reason I totally zoned out and finally understand what you mean. Yes, you're right! I should fix that.


I like the idea, I just haven't given it a try with the new draft yet. Sounds like it's worth exploring at the very least.


Cool! I'm glad you read my comment. I appreciate that you went through the effort to make a blog post (my comment is very low effort in comparison). I hope it came off as constructive.


The alternative is to do something like:

type Int int

func (i Int) Hash() uintptr { /* do the hash */ }

But I didn't want to deal with it in this code. I agree that it isn't optimal and would be curious to see if the situation can be improved.


Right, but you can only write strings or bytes to the hash, not integers, booleans, structs, etc. So the problem remains.


Exactly. Thanks!


Hey folks, presenter here! Happy to answer any questions you all may have, and thanks again to Sourcegraph for the live blog!


Great stuff!

This is actually a powerful design pattern in golang. Write first without worrying about bottlenecks. Make sure all tests are ok. And typically concurrent GC is performant enough for average loads.

Then later at our leisure we can optimize with pprof and custom load generator. With bonus points for go-fuzz and throwing in some chaos ;)

But for ARP style table lookups, do you even need to allocate for the response? Are we actually doing any request processing? Can't we just output the cache entry to the net io.Writer, log the event, and continue?


io.Writer takes a byte slice as an argument and the escape analyzer can’t see through the interface, so it would be allocated anyway, I believe.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: