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

Compute document's relative_path faster #6767

Merged
merged 2 commits into from Feb 28, 2018

Conversation

Projects
None yet
5 participants
@ashmaroli
Copy link
Member

commented Feb 12, 2018

Use String#sub instead of Pathutil#relative_path_from which uses regexes internally

Benchmark script:

#!/usr/bin/env ruby

require 'benchmark/ips'
require 'pathutil'

DOC_PATH = File.join(File.expand_path(__dir__), "_puppies", "rover.md")
COL_PATH = File.join(File.expand_path(__dir__), "_puppies")


def pathutil_relative
  Pathutil.new(DOC_PATH).relative_path_from(COL_PATH).to_s
end

def native_relative
  DOC_PATH.sub("#{COL_PATH}/", "")
end

if pathutil_relative == native_relative
  Benchmark.ips do |x|
    x.report("pathutil") { pathutil_relative }
    x.report("native")   { native_relative }
    x.compare!
  end
else
  print "PATHUTIL: "
  puts pathutil_relative
  print "NATIVE:   "
  puts native_relative
end

Note: Since Document#relative_path is a memoized function, the difference is noticeable only on large sites that containing a huge number of Documents

@pathawks
Copy link
Member

left a comment

Seems reasonable

@ashmaroli ashmaroli referenced this pull request Feb 17, 2018

Closed

Release 3.8.0 #6783

12 of 13 tasks complete

@DirtyF DirtyF requested a review from jekyll/performance Feb 17, 2018

@parkr

This comment has been minimized.

Copy link
Member

commented Feb 20, 2018

@ashmaroli Would you mind placing the benchmark script in the PR body into the repo?

~/jekyll/jekyll#master$ be ruby benchmark/pathutil-relative-vs-gsub.rb
Warming up --------------------------------------
            pathutil     5.992k i/100ms
              native    50.261k i/100ms
Calculating -------------------------------------
            pathutil     61.075k (± 8.6%) i/s -    305.592k in   5.042290s
              native    584.400k (± 5.4%) i/s -      2.915M in   5.001884s

Comparison:
              native:   584399.5 i/s
            pathutil:    61074.8 i/s - 9.57x  slower

@parkr

parkr approved these changes Feb 20, 2018

@ashmaroli

This comment has been minimized.

Copy link
Member Author

commented Feb 20, 2018

Would you mind placing the benchmark script in the PR body into the repo?

Sure.. not a problem.. 😃

@DirtyF

DirtyF approved these changes Feb 20, 2018

Copy link
Member

left a comment

Good catch!

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

@DirtyF

This comment has been minimized.

Copy link
Member

commented Feb 28, 2018

@jekyllbot: merge +minor

@jekyllbot jekyllbot merged commit 07e49f8 into jekyll:master Feb 28, 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

jekyllbot added a commit that referenced this pull request Feb 28, 2018

@ashmaroli ashmaroli deleted the ashmaroli:doc-relative-path branch Feb 28, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.