On 02/08/2013 08:52 AM, Eli Zaretskii wrote: >> > So, ~90% of time spent in scan_buffer is: >> > >> > 799 while (*cursor != target && --cursor >= ceiling_addr) >> > 800 ; > Which cannot be optimized. It can be sped up somewhat, by using memrchr. This won't solve these performance issues, but it helps: on my platform (x86-64 Ubuntu 12.10) I ran Dmitry's scroll-both benchmark on a real file (the trunk's src/xdisp.c), and it was 25% faster overall (1.19 seconds versus 1.49 seconds) when I used memrchr there and memchr for forward searches. I'll attach the patch I used. Eli, it'll need a bit of hacking to port to MS-Windows, since the substitute memrchr implementation (which is supplied) will need to be compiled. Dmitry, is this something you can easily try with your benchmarks? Most of the attached patch is boilerplate taken unmodified from gnulib, to support memrchr on non-GNU platforms. The key part of the change is at the end, to src/search.c.