4 ms·
Can someone speak to the difference between the two routes shown, and why exactly one is significantly more performant than the other? e.g. link_to 'hello', h
by doktrin 13y ago
Can someone speak to the difference between the two routes shown, and why exactly one is significantly more performant than the other?
e.g.
link_to 'hello', hello_index_url
vs.
link_to 'hello', controller: 'hello', action: 'index'
The fact that the first resolves orders of magnitude faster than the second seems counter intuitive.
- tomfakes 13y agoThe first form generates a method at startup time that can be pre-configured to do all the work necessary. The second form has to perform a pattern match with the controller and action names to work out which method to call, and then call the method generated by the first form. This extra pattern match is the overhead, and with thousands of routes, it clearly adds up. Always use named routes - the first form.