Closed jub0bs closed 3 hours ago
The CORS middleware currently recompiles the same regexps over and over during each of its invocations. However, for performance, compiling regexps on the hot path should be avoided when possible.
In this case, the regexps could be compiled once and for all during middleware initialisation. The following line
allowOriginPatterns := []string{}
could advantageously be replaced by
var allowOriginRegexp []*regexp.Regexp
and the rest of the necessary changes would flow from this simple change.
No regexp compilation on the hot path.
Regexp compilation on the hot path.
v4.12.0
Thanks for noticing. https://github.com/labstack/echo/pull/2709 reworks that part
Issue Description
The CORS middleware currently recompiles the same regexps over and over during each of its invocations. However, for performance, compiling regexps on the hot path should be avoided when possible.
In this case, the regexps could be compiled once and for all during middleware initialisation. The following line
could advantageously be replaced by
and the rest of the necessary changes would flow from this simple change.
Checklist
Expected behaviour
No regexp compilation on the hot path.
Actual behaviour
Regexp compilation on the hot path.
Version/commit
v4.12.0