| ▲ | lou1306 2 days ago | ||||||||||||||||
Question from someone trying to get better at Go: _before_ going all in with unsafe pointer operations, would it make sense to write a function harness & profile it with/without the -B flag to determine the actual impact of bounds check? | |||||||||||||||||
| ▲ | masklinn 2 days ago | parent | next [-] | ||||||||||||||||
Obviously. You also need to profile to make sure this is actually a hit spot, deploying unsafe to remove bounds checks which account for ~0% of runtime is a waste of effort. And as the essay mentions there are also “hints” you can give the compiler to fold bounds checks which may be sufficient. | |||||||||||||||||
| ▲ | ErroneousBosh 2 days ago | parent | prev | next [-] | ||||||||||||||||
Oh right so this is for the case where you say "I have given you an exactly known length of data to buzz round a million times, you don't needs to bounds check every time"? Like, I have a hardcoded 1024-byte buffer, my loop is hardcoded so its index increases modulo 1024, it can never run off the end any more than you can overtake your own bike chain? | |||||||||||||||||
| ▲ | 5701652400 2 days ago | parent | prev [-] | ||||||||||||||||
probably you do not need to do any of that. better at Go to ship apps — none of that needed. actually opposite. the less complexity and low level details you hardcode yourself, the better. chances are, this low-level tech debt will bite you back when you have no time to deal with it. keep it simple. better at Go to work with internals of Go/compilers/runtime — yes, but do you plan to ship one? or why it is needed at all? or do you work at Go core at Google? | |||||||||||||||||
| |||||||||||||||||