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

Access document permalink attribute efficiently #6740

Merged
merged 1 commit into from Mar 21, 2018

Conversation

Projects
None yet
6 participants
@ashmaroli
Member

ashmaroli commented Feb 4, 2018

Currently Renderer#permalink_ext calls document.permalink 3 times per document instance which results in accessing a non-memoized method involving conditional traversing,,

# The permalink for this Document.
# Permalink is set via the data Hash.
#
# Returns the permalink or nil if no permalink was set in the data.
def permalink
data && data.is_a?(Hash) && data["permalink"]
end

While a better approach would be to additionally cache the permalink value within the Document instance itself, I'm deferring that for cases that may be altering the permalink via a :post_render hook using plugins..

@parkr

In other PR’s, you memoize inside the method. Why approach this differently with a temporary variable? Just curious :)

@ashmaroli

This comment has been minimized.

Member

ashmaroli commented Feb 5, 2018

Why approach this differently with a temporary variable?

I mentioned my doubts in the OP. In case you missed it, I elected for this accommodate for a scenario where a plugin would be altering the document's permalink via a :post_render hook..
(Just being cautious..)

@pathawks pathawks requested a review from jekyll/performance Feb 6, 2018

@ashmaroli

This comment has been minimized.

Member

ashmaroli commented Feb 6, 2018

@pathawks Since you asked..
every time an instance calls document.permalink, the sequence of data && data.is_a?(Hash) && data["permalink"] is executed.. which (according to me) is kinda expensive call because of the checks involved..
Now ideally, a Rubyist aiming for gain in performance would simply address this situation using memoization.. but here, I opted to defer memoization and implement the next best thing being (strangulate before Document instance is invoked..) to cache the value of document.permalink in a local variable

@pathawks

This comment has been minimized.

Member

pathawks commented Feb 6, 2018

@ashmaroli I follow.

Sorry, I didn’t thoroughly read your original post. I understand now why this is helpful. 👍

@Crunch09

👍

@ashmaroli ashmaroli referenced this pull request Feb 17, 2018

Closed

Release 3.8.0 #6783

12 of 13 tasks complete

@ashmaroli ashmaroli added this to the v3.8.0 milestone Mar 20, 2018

@oe

This comment has been minimized.

Member

oe commented Mar 21, 2018

@jekyllbot: merge +dev

@jekyllbot jekyllbot merged commit 8c6433b into jekyll:master Mar 21, 2018

3 checks passed

WIP ready for review
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@ashmaroli ashmaroli deleted the ashmaroli:reduce-external-attr-check branch Mar 21, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment