25 Apr '16, 7am

Speed up String#blank? Regex by schneems · Pull Request #24658 · rails/rails · GitHub: Follow up on 697384d… https://t.co/a3yyUH8q3u

[email protected] #commitcomment-17184696 . The regex to detect a blank string `/\A[[:space:]]*\z/` will loop through every character in the string to ensure that all of them are a `:space:` type. We can invert this logic and instead look for any non-`:space:` characters. When that happens, we would return on the first character found and the regex engine does not need to keep looking. Thanks @nellshamrell for the regex talk at LSRC. By defining a "blank" string as any string that does not have a non-whitespace character (yes, double negative) we can get a substantial speed bump. Also an inline regex is (barely) faster than a regex in a constant, since it skips the constant lookup. A regex literal is frozen by default. ```ruby require 'benchmark/ips' def string_generate str = " abcdefghijklmnopqrstuvwxyz\t".freeze str[rand(0..(str.length - 1))] * rand(0..23) end strings = 100....

Full article: https://github.com/rails/rails/pull/24658

Tweets

~3.5x speedup of String#blank? for empty string...

github.com 25 Apr '16, 7am

See the rationale in the comment in this patch. To benchmark this I ran a number of variations, ultimately narrowing to re...

ruby: Add support for specifying comments for t...

github.com 24 Apr '16, 11pm

For example in my work recently was situation when we were need to send documentation to customer and database schema was ...

This week in Rails: Speed improvements, databas...

weblog.rubyonrails.org 24 Apr '16, 4am

Hello everyone! Prathamesh here bringing you This Week in Rails. Let’s get started. Featured