Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PageDrop to provide Liquid templates with data #7992

Merged
merged 7 commits into from Mar 26, 2020

Conversation

ashmaroli
Copy link
Member

Background

Currently Jekyll::Page#to_liquid is an unmemoized method that returns the Hash representation of a given Jekyll::Page instance. The current approach is wasteful because:

  • the method is unmemoized.
  • generating the Hash representation involves resolving all content methods (not all of them are memoized) even if they're not required in a template.

Proposed Solution

  • Switch to using a Liquid::Drop subclass like other Core classes. (Memoizing the method might complicate it).
  • To avoid changing the contract for Page subclasses, alias existing implementation as a private method which will be called if the subclass doesn't already override the :to_liquid method.
  • To allow voluntary migration to using the superclass drop in subclasses, the subclass may override their :to_liquid definition to wrap the private method :liquid_drop:
    class FooPage < Jekyll::Page
      def to_liquid
        liquid_drop
      end
    end

@mattr-
Copy link
Member

mattr- commented Feb 6, 2020

The current approach is wasteful

Waste isn't necessarily bad, particularly when the method in question works and the way it works is the least surprising way for it to work.

the method is unmemoized

Why is this bad? Why would memoizing it be better? How does a long running Jekyll instance with this data memoized affect the user experience? For the last question, I'm concerned mostly with what happens if the data underneath changes.

generating the Hash representation involves resolving all content methods (not all of them are memoized) even if they're not required in a template.

Again, on the surface, this doesn't necessarily seem like a bad idea. Why is resolving all content methods bad?

@ashmaroli
Copy link
Member Author

Why is this bad? Why would memoizing it be better? Why is resolving all content methods bad?

@mattr- I think the best way to answer this is by adding a couple of tests involving a fixture site with lots of standalone pages. But, it needs to come in through the master branch so that we can compare with this branch..

I'm concerned mostly with what happens if the data underneath changes.

Valid concern and a good one at that. I'll add a Cucumber test to check if there's a problem there
and make changes if necessary.

@mattr-
Copy link
Member

mattr- commented Feb 6, 2020

I think the best way to answer this is by adding a couple of tests involving a fixture site with lots of standalone pages.

How is this the best way? Just explain in a comment what you're actually doing with these changes and the motivation behind making them.

Valid concern and a good one at that. I'll add a Cucumber test to check if there's a problem there and make changes if necessary.

How is a test going to help here?

@ashmaroli
Copy link
Member Author

How is this the best way? Just explain in a comment what you're actually doing with these changes and the motivation behind making them.

Jekyll::Document, Jekyll::StaticFile instances expose themselves to layouts via respective Liquid::Drops. This PR proposes to move Jekyll::Page into the same boat.

The primary intention (and motivation) with this is to reduce memory usage in a site with numerous standalone pages.

@mattr-
Copy link
Member

mattr- commented Feb 6, 2020

Jekyll::Document, Jekyll::StaticFile instances expose themselves to layouts via respective Liquid::Drops. This PR proposes to move Jekyll::Page into the same boat.

The primary intention (and motivation) with this is to reduce memory usage in a site with numerous standalone pages

Perfect! This is exactly the background information I was looking for. 😄 Thanks!

+1 from me.

@ashmaroli ashmaroli added this to the 4.1 milestone Mar 16, 2020
docs/_docs/pages.md Outdated Show resolved Hide resolved
Co-Authored-By: Frank Taillandier <frank.taillandier@gmail.com>
@ashmaroli ashmaroli requested a review from DirtyF March 22, 2020 09:11
Copy link
Member

@DirtyF DirtyF left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 for cohesiveness. What are the official plugins possibly impacted by this change?

@ashmaroli
Copy link
Member Author

ashmaroli commented Mar 22, 2020

What are the official plugins possibly impacted by this change?

This is a backwards-compatible change. However, should there be an effect, it would be in
jekyll-archives, jekyll-feed, jekyll-sitemap, jekyll-redirect-from..

@ashmaroli
Copy link
Member Author

@jekyllbot: merge +minor

@jekyllbot jekyllbot merged commit b84ba5a into jekyll:master Mar 26, 2020
@ashmaroli ashmaroli deleted the add-page-drop branch March 26, 2020 13:39
jekyllbot added a commit that referenced this pull request Mar 26, 2020
@jekyll jekyll locked and limited conversation to collaborators Mar 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants