Re:I want off Mr. Golang’s Wild Ride (2020)
by masklinn on Thursday April 28, 2022 @02:40PM
(#31196491)
> Errors as return values is only acceptable for code that is so performance-sensitive that you aren't allowed to do dynamic memory allocations.
Exceptions-based code can be zero-cost, if no errors occur, at an increased error-case cost. Using error values pessimises this, and increase branch prediction load (as every callsite is now a branch).
So in the common case where errors are extremely rare, exceptions-based error handling can be quite a bit faster than return-value error handling.
Which doesn't mean it's preferable, but beware thinking that return values are faster.
Exceptions-based code can be zero-cost, if no errors occur, at an increased error-case cost. Using error values pessimises this, and increase branch prediction load (as every callsite is now a branch).
So in the common case where errors are extremely rare, exceptions-based error handling can be quite a bit faster than return-value error handling.
Which doesn't mean it's preferable, but beware thinking that return values are faster.