The time the x86 emulator team found code so bad they fixed it during emulation(devblogs.microsoft.com)
492 points by paulmooreparks 1 day ago | 168 comments
tl;dr: A Windows x86-32 binary translation emulator team encountered a program that allocated 64KB on the stack and initialized it by unrolling the init loop into 65,536 individual byte-write instructions—256KB of code to zero 64KB of data. Rather than faithfully translating this monstrosity, the team added special-case detection to recognize the pattern and replace it with an equivalent tight loop during translation.
HN Discussion:
  • Sharing similar war stories of inefficient code discovered while working on tooling or emulation layers
  • Compatibility/translation layers fixing broken software is a recurring and valuable pattern
  • Questioning the article's framing—loop unrolling may actually be a legitimate optimization choice
  • ~Correcting or nuancing the article's claim about the 'standard way' of stack allocation
  • Broader lamentation about pervasive unoptimized code in modern software