Optimize loading library into memory (#6910)

Merge pull request 6910
This commit is contained in:
ashmaroli 2018-04-10 20:30:12 +05:30 committed by jekyllbot
parent ef027be97e
commit 36fbcaa863
15 changed files with 35 additions and 27 deletions

29
benchmark/local-require Executable file
View File

@ -0,0 +1,29 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'benchmark/ips'
require 'jekyll'
require 'json'
DATA = {"foo"=>"bar", "alpha"=>{"beta"=>"gamma"}, "lipsum"=>["lorem", "ipsum", "dolor"]}
def local_require
require 'json'
JSON.pretty_generate(DATA)
end
def global_require
JSON.pretty_generate(DATA)
end
def graceful_require
Jekyll::External.require_with_graceful_fail("json")
JSON.pretty_generate(DATA)
end
Benchmark.ips do |x|
x.report("local-require") { local_require }
x.report("global-require") { global_require }
x.report("graceful-require") { graceful_require }
x.compare!
end

View File

@ -18,7 +18,6 @@ end
require "rubygems"
# stdlib
require "pathutil"
require "forwardable"
require "fileutils"
require "time"
@ -26,8 +25,12 @@ require "English"
require "pathname"
require "logger"
require "set"
require "csv"
require "json"
# 3rd party
require "pathutil"
require "addressable/uri"
require "safe_yaml/load"
require "liquid"
require "kramdown"

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require "set"
module Jekyll
# Handles the cleanup of a site's destination before it is built.
class Cleaner

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require "addressable/uri"
module Jekyll
module Commands
class Doctor < Command

View File

@ -1,6 +1,5 @@
# frozen_string_literal: true
require "json"
require "em-websocket"
require_relative "websockets"

View File

@ -14,9 +14,6 @@ module Jekyll
}.freeze
def initialize(config)
unless defined?(Kramdown)
Jekyll::External.require_with_graceful_fail "kramdown"
end
@main_fallback_highlighter = config["highlighter"] || "rouge"
@config = config["kramdown"] || {}
@highlighter = nil

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require "set"
# Convertible provides methods for converting a pagelike item
# from a certain type of markup into actual content
#

View File

@ -137,7 +137,6 @@ module Jekyll
#
# Returns a pretty generation of the hash representation of the Drop.
def inspect
require "json"
JSON.pretty_generate to_h
end
@ -155,7 +154,6 @@ module Jekyll
#
# Returns a JSON representation of the Drop in a String.
def to_json(state = nil)
require "json"
JSON.generate(hash_for_json(state), state)
end

View File

@ -25,7 +25,6 @@ module Jekyll
end
def to_json(state = nil)
require "json"
JSON.generate(to_h, state)
end
end

View File

@ -1,9 +1,5 @@
# frozen_string_literal: true
require "addressable/uri"
require "json"
require "liquid"
require_all "jekyll/filters"
module Jekyll

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require "addressable/uri"
module Jekyll
module Filters
module URLFilters

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require "csv"
module Jekyll
class Reader
attr_reader :site

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require "csv"
module Jekyll
class Site
attr_reader :source, :dest, :config

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require "addressable/uri"
# Public: Methods that generate a URL for a resource such as a Post or a Page.
#
# Examples

View File

@ -1,11 +1,12 @@
# frozen_string_literal: true
Jekyll::External.require_with_graceful_fail("rouge")
module Jekyll
module Utils
module Rouge
def self.html_formatter(*args)
Jekyll::External.require_with_graceful_fail("rouge") unless defined?(::Rouge)
if old_api?
::Rouge::Formatters::HTML.new(*args)
else