$ the-wire · showcase
ActionDispatch drops regexp re-serialization per ParameterFilter build
By RepoJournal · Filed · About Rails
Rails replaced Regexp#to_s with Regexp#source in ParameterFilter#compile_filters!, removing per-call regexp re-serialization and re-compilation overhead on every ActionDispatch request.
ParameterFilter#compile_filters! used Regexp#to_s to check whether pattern text contains an escaped dot, which re-serializes and partially re-compiles the regexp on every call. It now uses Regexp#source, a plain accessor, returning the same answer without the extra work [1]. This matters because ActionDispatch builds a new ParameterFilter per request, so the savings show up in benchmarks like railsbench [1]. The change was merged into Rails via pull request #58678 [2].
Action items
References