Use custom visitor class for optimized url helpers

Rather than trying to use gsub to remove the optional route segments,
which will fail with nested optional segments, use a custom visitor
class that returns a empty string for group nodes.

Closes #9524
Bring config.allow_concurrency back

Since the Rack::Lock still exists in development,
let's provide a way to disable it explicitly.