Fast(er) regular expression engines in Ruby
serpapi.com
Fast(er) regular expression engines in Ruby
1–7 of 7 posts
Re: Fast(er) regular expression engines in Ruby
#2Re: Fast(er) regular expression engines in Ruby
#3Re: Fast(er) regular expression engines in Ruby
#4This is extremely basic ruby: UTF-8 encoded strings must be valid UTF-8. This is not unique to ruby. If I recall correctly, python 3 does the same thing.
2.7.1 :001 > haystack = "\xfc\xa1\xa1\xa1\xa1\xa1abc"
2.7.1 :003 > haystack.force_encoding "ASCII-8BIT"
=> "\xFC\xA1\xA1\xA1\xA1\xA1abc"
2.7.1 :004 > haystack.scan(/.+/)
=> ["\xFC\xA1\xA1\xA1\xA1\xA1abc"]
This person is a senior engineer on their Team page. All they had to do was google "ArgumentError: invalid byte sequence in UTF-8". Or ask a coworker... the company has Ruby on Rails applications. headdeskRe: Fast(er) regular expression engines in Ruby
#5> Another nuance was found in ruby, which cannot scan the haystack with invalid UTF-8 byte sequences. This is extremely basic ruby: UTF-8 encoded strings must be valid UTF-8. This is not unique to ruby. If I recall correctly, python 3 does the same thing. 2.7.1 :001 > haystack = "\xfc\xa1\xa1\xa1\xa1\xa1abc" 2.7.1 :003 > haystack.force_encoding "ASCII-8BIT" => "\xFC\xA1\xA1\xA1\xA1\xA1abc" 2.7.1 :004 > haystack.scan(…
Re: Fast(er) regular expression engines in Ruby
#6> Another nuance was found in ruby, which cannot scan the haystack with invalid UTF-8 byte sequences. This is extremely basic ruby: UTF-8 encoded strings must be valid UTF-8. This is not unique to ruby. If I recall correctly, python 3 does the same thing. 2.7.1 :001 > haystack = "\xfc\xa1\xa1\xa1\xa1\xa1abc" 2.7.1 :003 > haystack.force_encoding "ASCII-8BIT" => "\xFC\xA1\xA1\xA1\xA1\xA1abc" 2.7.1 :004 > haystack.scan(…
The nuance is specifically relevant here because neither of the other two regex engines benchmarked have this requirement. It's doubly relevant because that means running a regex search doesn't require a UTF-8 validation step, and is therefore likely beneficial from a perf perspective, dependening on the workload.
Edit: After a little testing, the strings can be read from and written to files without triggering validation. Presumably this applies to sockets as well.