rails icon indicating copy to clipboard operation
rails copied to clipboard

WIP: Add a cache per-request partial lookup cache to lookup context

Open jhawthorn opened this issue 3 years ago • 0 comments

This adds a fast path for partial lookup on "simple" partial renders.

In this case "simple" means:

  1. This is a plain partial render, like render "foo", {...} or render partial: "foo", locals: {...}
  2. No details are specified (format, handler, locale, variant)
  3. No block is given (the "layout" form)

When this is the case, this allows a few improvements:

  1. We cache any simple partial we find in the LookupContext. The LookupContext should only exists for the length of the request and the cache is cleared whenever any details, prefixes, or template paths are changed on the lookup context.
  2. We go through a new SimplePartialRenderer class, which skips some of the work done in the regular PartialRenderer (string manipulation of the path/prefix, and building an hash for the options). A relatively minor optimization compared to 1, but very measurable.

cc @byroot

jhawthorn avatar Sep 07 '22 03:09 jhawthorn