perf: optimize content extension checking in router#1391
Conversation
|
The performance intent is sound — the 606-alternation Two confirmed divergences (reproduced against the exact original regex on Crystal 1.20.0):
Bare minimum we'll acceptThe optimized code must produce identical results to the pre-PR anchored-regex behavior for every input below, each covered by a spec (in
Plus one structural ask:
Beyond the minimumIf you can identify additional edge cases worth locking down — e.g. percent-encoded dots ( Once #1–#7 hold with green specs, we're happy to take the optimization. |
|
I have updated the PR to address your feedback. Following your suggestions, I avoided All specs are passing. (Note: This contribution was co-developed with Gemini AI. Rénich has directed, reviewed, tested, and takes full responsibility for this code.) |
Replaced slow Regex matching `str.match(/\.(html|json|txt|...)$/)` with fast string manipulation and hash lookups (`File.extname` + `.has_key?`). This drastically speeds up router matching and content type parsing. Co-authored-by: renich <225115+renich@users.noreply.github.com>
Refactor route matching and responder extension checking to use rindex and custom key sets. This matches the behavior of the original regex anchoring while avoiding File.extname bugs (such as trailing slashes, leading-dot file basenames, and case-insensitivity bugs). Co-developed-by: Gemini AI <renich+gemini@woralelandia.com> Signed-off-by: Rénich Bon Ćirić <renich@woralelandia.com>
00fd908 to
ba1ee41
Compare
Uses File.extname and Hash lookup instead of regular expression alternation for file extension checking in hot paths.
Co-developed-by: Gemini AI renich+gemini@woralelandia.com
Signed-off-by: Rénich Bon Ćirić renich@woralelandia.com