The hack that improves your tungstunite-rs performance by 160x

From the article:

always_returns_true is a function that, clearly, will return true for any possible 8-bit unsigned integer. After all, every possible value for x will be either less than 120, equal to 120, or bigger than 120. A quick loop confirms this. However, if you run the example, you can see the assertion fail.

This is circular logic. The only reason the function returns false is because the compiler notices undefined behaviour. If the language didn’t say reading uninitialized memory is undefined behaviour (but rather said that it’s unspecified and that the variable can have any possible value) the compiler would not be allowed this optimisation.

And to be clear what I’m talking about are primitive types and even more specifically integer types. Reading anything else uninitialized should remain undefined behaviour.

/r/rust Thread Parent