News for hackers. Stuff that matters.
Re:Why is it faster to process a sorted array than an unsort... by rwmj on Saturday May 18, 2019 @10:23AM (#19947528)
I had a fun accidental optimization last week: I needed to zero out a memory buffer before calling a GnuTLS function to read in data (for security reasons - we can't be sure that the callee will fill in the full buffer and don't want to leak uninitialized memory back to the client). I wondered what the performance penalty of this would be. In fact it made the code about 5-10% faster. This is on the edge of being a measurable effect - could be random variability in the test - but it certainly surprised me that it was not slower.

The non-encrypted transport case had a similar change but there was no measurable performance difference before and after.

I'd like to know what perf stats are available to show what's going on. (I guess it's an L2 cache effect)

Re:Why is it faster to process a sorted array than an unsort... by manilafolder on Saturday May 18, 2019 @01:15PM (#19948504)
Hi, for Intel processors, the renamer can detect instructions that will always result in a zero (zero-idioms or dependency breaking idioms). As a result, the renamer will not send the instruction to the execution engine.

Basically, just think of this as repointing your registers to a register that's always zero. Note this only appears for the value zero.

This is one of the reasons you're supposed to wipe out sensitive data with random numbers, not zeros.

Also note that your compiler may copy data to the stack whenever it wants to. So even wiping out data with random numbers may not wipe out the copied data that lives (momentarily) on the stack.

https://webcourse.cs.technion.ac.il/234267/Winter2015-2016/h...

Re:Why is it faster to process a sorted array than an unsort... by seanmcdirmid on Saturday May 18, 2019 @10:59AM (#19947757)
The zeroing was somehow priming the cache, maybe it was faster this way because all the zero writes were independent and could easily be run in parallel, whereas normal cache stalls would cause more actual stalling.
Re:Why is it faster to process a sorted array than an unsort... by gameswithgo on Saturday May 18, 2019 @12:33PM (#19948286)
prolly a simd enhanced zero operation so very quick.