Project

General

Profile

« Previous | Next » 

Revision e7cb70be

Added by [email protected] (Zack Deveau) 10 months ago

Improve String#rindex performance on OSX

On OSX, String#rindex is slow due to the lack of memrchr.
The fallback implementation finds a match by instead doing
a memcmp on every single character in the search string
looking for a substring match.

For OSX hosts, this changeset introduces a simple memrchr
implementation, rb_memrchr, that can be used instead. An
example benchmark below demonstrates an 8000 char long
search string with a 10 char substring near the end.

ruby-master | substring near the end | osx

UTF-8
       user     system      total        real
index  0.000111   0.000000   0.000111 (  0.000110)
rindex  0.000446   0.000005   0.000451 (  0.000454)
ruby-patched | substring near the end | osx

UTF-8
       user     system      total        real
index  0.000112   0.000000   0.000112 (  0.000111)
rindex  0.000057   0.000001   0.000058 (  0.000057)