What is this asm style “x | 0” some javascript programmers are now using?

According to JavaScript Performance for Madmen Wrapping integer arithmetic expressions in ( ) | 0 allows the runtime to be sure that you’re doing integer arithmetic instead of floating-point arithmetic. This allows it to avoid checking for overflow and produce faster code in many cases. and according to the page, it’s true for “most” Javascript … Read more

VS: unexpected optimization behavior with _BitScanReverse64 intrinsic

AFAICT, the intrinsic leaves garbage in index when the input is zero, weaker than the behaviour of the asm instruction. This is why it has a separate boolean return value and integer output operand. Despite the index arg being taken by reference, the compiler treats it as output-only. unsigned char _BitScanReverse64 (unsigned __int32* index, unsigned … Read more

how to replace characters in a array quickly

The reason that it spends so much time in that line is because the Contains method loops through the array to look for the character. Put the characters in a HashSet<char> instead: private static HashSet<char> badChars = new HashSet<char>(new char[] { ‘\x00’, ‘\x09’, ‘\x0A’, ‘\x10’ }); The code to check if the set contains the … Read more