Rewrites regex compilation heap allocation and CPU time is high

Looking at the profiler for CPU time, heap size and heap allocations for redirects.Rewrite. We can see that the call to regexp.Compile has a high performance effect on the redirects feature.

CPU Time for 1 day before the FF_ENABLE_PLACEHOLDERS feature flag was enabled.

cpu_time_before

After

cpu_time_after


Heap size before

heap_size_before

Heap size after

heap_size_after


Allocated heap before

heap_allocations_before

After

heap_allocations_after


The increase is quite significant but the good news is we will only come here if:

  1. The resource being accessed does not exist, and
  2. The project has a _redirects file, and
  3. A simple redirect rule does not match first, and
  4. A splat/placeholder rule exists.

The increase seen above is probably due to docs.gitlab.com having enabled splats for all resources under /ce/* to redirect to /ee/:splat in gitlab-docs!2094 (merged).

So this is not a dealbreaker in my opinion, but it's certainly something to keep an eye on.

Edited by Jaime Martinez