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

Memoize relative_url for performance gains #914

Closed
MaxLap opened this issue Sep 2, 2024 · 1 comment · Fixed by #915
Closed

Memoize relative_url for performance gains #914

MaxLap opened this issue Sep 2, 2024 · 1 comment · Fixed by #915
Labels
bug Something isn't working

Comments

@MaxLap
Copy link

MaxLap commented Sep 2, 2024

My 250 pages site has a sidebar which links to every/most pages. I was tired to building the site taking so long, so after a bit of profiling, I noticed that #relative_url isn't memoized. So every link needs to rebuild the same relative urls.

Memoizing with the following in my config/initializers.rb made my build time go from 10s to 5s.

module MemoizeRelativeUrl
  def relative_url
    @relative_url ||= super
  end
end
Bridgetown::Resource::Base.prepend(MemoizeRelativeUrl)

I don't know if a relative_url is meant to change over the course of a build, but if it isn't, this is a massive usability improvement for me.

I don't know if the change should be on Bridgetown::Resource::Base or Bridgetown::Resource::Destination or somewhere else, but I think there should definitely be memoization somewhere.

@MaxLap MaxLap added the bug Something isn't working label Sep 2, 2024
jaredcwhite added a commit that referenced this issue Sep 6, 2024
jaredcwhite added a commit that referenced this issue Sep 6, 2024
* Memoize resource URLs for major performance gain

Resolves #914

* Actually memoize this time
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants
@MaxLap and others