lieff / minimp4

Minimalistic MP4 mux/demux single header library
Creative Commons Zero v1.0 Universal
342 stars 58 forks source link

Replace search for zero byte with memchr() #19

Closed jhurliman closed 4 years ago

jhurliman commented 4 years ago

While profiling minimp4 during MP4 encoding, find_start_code showed up as the most expensive function. Specifically, the first while loop searching for an initial zero byte. This is effectively what memchr() does, and glibc includes an optimized version of this method. Switching to memchr() showed a performance improvement in this method.

lieff commented 4 years ago

Good catch :) Later I want to redesign h26x writer so it can accept already splitted nals which for example x264 can provide.