Skip to content

Improve performance of route matching

Heinrich Lee Yu requested to merge improve-route-matching into master

While looking at some flamegraphs of API requests, I noticed several times that GrapePathHelpers::NamedRouteMatcher#route_match? was one of the methods with the highest durations.

Screen_Shot_2021-05-07_at_2.07.35_AM

Screen_Shot_2021-05-07_at_2.07.09_AM

It's not that bad all the time, but even on good runs it's still one of the top ones:

Screen_Shot_2021-05-07_at_2.34.23_AM

This method is used to generate API links, specially these _links that are always present in our responses:

Screen_Shot_2021-05-07_at_2.27.06_AM

This MR attempts to optimize this by stringifying the arguments only once.

This also improves the uses_segments_in_path_helper? check by using the memoized required_helper_segments in DecoratedRoute

Edited by Heinrich Lee Yu

Merge request reports