Skip to content

Commit

Permalink
Reduce Jekyll::Renderer instances during a build (#7570)
Browse files Browse the repository at this point in the history
Merge pull request 7570
  • Loading branch information
ashmaroli committed Apr 13, 2020
1 parent ffdab93 commit e42c35c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
30 changes: 15 additions & 15 deletions lib/jekyll/convertible.rb
Expand Up @@ -78,23 +78,23 @@ def validate_permalink!(filename)
#
# Returns the transformed contents.
def transform
_renderer.convert(content)
renderer.convert(content)
end

# Determine the extension depending on content_type.
#
# Returns the String extension for the output file.
# e.g. ".html" for an HTML output file.
def output_ext
_renderer.output_ext
renderer.output_ext
end

# Determine which converter to use based on this convertible's
# extension.
#
# Returns the Converter instance.
def converters
_renderer.converters
renderer.converters
end

# Render Liquid in the content
Expand All @@ -105,7 +105,7 @@ def converters
#
# Returns the converted content
def render_liquid(content, payload, info, path)
_renderer.render_liquid(content, payload, info, path)
renderer.render_liquid(content, payload, info, path)
end

# Convert this Convertible's data to a Hash suitable for use by Liquid.
Expand Down Expand Up @@ -191,10 +191,10 @@ def invalid_layout?(layout)
#
# Returns nothing
def render_all_layouts(layouts, payload, info)
_renderer.layouts = layouts
self.output = _renderer.place_in_layouts(output, payload, info)
renderer.layouts = layouts
self.output = renderer.place_in_layouts(output, payload, info)
ensure
@_renderer = nil # this will allow the modifications above to disappear
@renderer = nil # this will allow the modifications above to disappear
end

# Add any necessary layouts to this convertible document.
Expand All @@ -204,15 +204,15 @@ def render_all_layouts(layouts, payload, info)
#
# Returns nothing.
def do_layout(payload, layouts)
self.output = _renderer.tap do |renderer|
renderer.layouts = layouts
renderer.payload = payload
self.output = renderer.tap do |doc_renderer|
doc_renderer.layouts = layouts
doc_renderer.payload = payload
end.run

Jekyll.logger.debug "Post-Render Hooks:", relative_path
Jekyll::Hooks.trigger hook_owner, :post_render, self
ensure
@_renderer = nil # this will allow the modifications above to disappear
@renderer = nil # this will allow the modifications above to disappear
end

# Write the generated page file to the destination directory.
Expand Down Expand Up @@ -241,12 +241,12 @@ def [](property)
end
end

private

def _renderer
@_renderer ||= Jekyll::Renderer.new(site, self)
def renderer
@renderer ||= Jekyll::Renderer.new(site, self)
end

private

def no_layout?
data["layout"] == "none"
end
Expand Down
6 changes: 5 additions & 1 deletion lib/jekyll/document.rb
Expand Up @@ -116,7 +116,7 @@ def relative_path
#
# Returns the output extension
def output_ext
@output_ext ||= Jekyll::Renderer.new(site, self).output_ext
renderer.output_ext
end

# The base filename of the document, without the file extname.
Expand All @@ -133,6 +133,10 @@ def basename
@basename ||= File.basename(path)
end

def renderer
@renderer ||= Jekyll::Renderer.new(site, self)
end

# Produces a "cleaned" relative path.
# The "cleaned" relative path is the relative path without the extname
# and with the collection's directory removed as well.
Expand Down
3 changes: 2 additions & 1 deletion lib/jekyll/site.rb
Expand Up @@ -520,7 +520,8 @@ def render_pages(payload)
def render_regenerated(document, payload)
return unless regenerator.regenerate?(document)

document.output = Jekyll::Renderer.new(self, document, payload).run
document.renderer.payload = payload
document.output = document.renderer.run
document.trigger_hooks(:post_render)
end
end
Expand Down

0 comments on commit e42c35c

Please sign in to comment.