Moving Imports And Partials? Which One Is Faster?

Dear All

I used Jekyll before I migrated to Hugo. On my Jekyll before, I avoid using so many liquid and includes method, because it will open the file that I includes, and it takes more time to build.

I know that most of Hugo themes uses imports and partials for easier development purpose. But I want more simpler file and structure. So, I move most of the code inside imports and partials to the parents file.

My question:
Does moving the code inside imports and partials to the parents file can improve performance and building time? Which one is faster?

Regards

You can test yourself by using the options:

--templateMetrics --templateMetricsHints
2 Likes

Hugo is really fast so there is less need to worry about this.

Having a lot of partials in e.g. baseof.html compered to adding it all directly will have an (small) impact. Use the options @zwbetz suggested to see how much.

I think a sensible use of partials makes templates like baseof.html easier to read and understand.

Partials can also improve performance a lot, read up on partialCached.

2 Likes

Thanks for response. Bit worry because of slow Jekyll building time on the past.

Here’s my current build results ->

3:08:24 PM: Build ready to start
3:08:27 PM: build-image version: 9e0f207a27642d0115b1ca97cd5e8cebbe492f63
3:08:27 PM: build-image tag: v3.3.2
3:08:27 PM: buildbot version: ef8d0929ed0baabafd8bbb7d0b021e1fc24180c0
3:08:27 PM: Fetching cached dependencies
3:08:27 PM: Starting to download cache of 119.0MB
3:08:28 PM: Finished downloading cache in 877.059013ms
3:08:28 PM: Starting to extract cache
3:08:31 PM: Finished extracting cache in 3.671813064s
3:08:31 PM: Finished fetching cache in 4.581074372s
3:08:31 PM: Starting to prepare the repo for build
3:08:32 PM: Preparing Git Reference refs/heads/master
3:08:33 PM: Found netlify.toml. Overriding site configuration
3:08:33 PM: Different publish path detected, going to use the one specified in the toml file: 'public' versus '/' in the site
3:08:33 PM: Different build command detected, going to use the one specified in the toml file: 'hugo --gc --minify' versus '' in the site
3:08:33 PM: Starting build script
3:08:33 PM: Installing dependencies
3:08:33 PM: Started restoring cached node version
3:08:36 PM: Finished restoring cached node version
3:08:37 PM: v10.16.3 is already installed.
3:08:38 PM: Now using node v10.16.3 (npm v6.9.0)
3:08:38 PM: Attempting ruby version 2.6.2, read from environment
3:08:40 PM: Using ruby version 2.6.2
3:08:40 PM: Using PHP version 7.2
3:08:40 PM: Installing Hugo 0.57.2
3:08:40 PM: Hugo Static Site Generator v0.57.2-A849CB2D/extended linux/amd64 BuildDate: 2019-08-17T17:57:54Z
3:08:40 PM: Started restoring cached go cache
3:08:40 PM: Finished restoring cached go cache
3:08:40 PM: unset GOOS;
3:08:40 PM: unset GOARCH;
3:08:40 PM: export GOROOT='/opt/buildhome/.gimme/versions/go1.12.linux.amd64';
3:08:40 PM: export PATH="/opt/buildhome/.gimme/versions/go1.12.linux.amd64/bin:${PATH}";
3:08:40 PM: go version >&2;
3:08:40 PM: export GIMME_ENV='/opt/buildhome/.gimme/env/go1.12.linux.amd64.env';
3:08:40 PM: go version go1.12 linux/amd64
3:08:40 PM: Installing missing commands
3:08:40 PM: Verify run directory
3:08:40 PM: Executing user command: hugo --gc --minify
3:08:40 PM: Building sites …
3:08:40 PM: WARN 2019/08/18 08:08:40 Page's .URL is deprecated and will be removed in a future release. Use .Permalink or .RelPermalink. If what you want is the front matter URL value, use .Params.url.
3:08:40 PM: WARN 2019/08/18 08:08:40 found no layout file for "HTML" for "taxonomyTerm": You should create a template file which matches Hugo Layouts Lookup Rules for this combination.
3:08:40 PM: WARN 2019/08/18 08:08:40 found no layout file for "HTML" for "section": You should create a template file which matches Hugo Layouts Lookup Rules for this combination.
3:08:40 PM: WARN 2019/08/18 08:08:40 found no layout file for "HTML" for "taxonomyTerm": You should create a template file which matches Hugo Layouts Lookup Rules for this combination.
3:08:40 PM:                    |
3:08:40 PM:  EN
3:08:40 PM: +------------------+----+
3:08:40 PM:   Pages            | 37
3:08:40 PM:   Paginator pages  |
3:08:40 PM:  3
3:08:40 PM:   Non-page files   |  0
3:08:40 PM:   Static files     |  5
3:08:40 PM:   Processed images |  0
3:08:40 PM:   Aliases
3:08:40 PM:  |  3
3:08:40 PM:   Sitemaps         |  1
3:08:40 PM:   Cleaned          |  0
3:08:41 PM: Starting post processing
3:08:40 PM: Total in 56 ms
3:08:40 PM: Skipping functions preparation step: no functions directory set
3:08:40 PM: Caching artifacts
3:08:40 PM: Started saving pip cache
3:08:41 PM: Finished saving pip cache
3:08:41 PM: Started saving emacs cask dependencies
3:08:41 PM: Finished saving emacs cask dependencies
3:08:41 PM: Started saving maven dependencies
3:08:41 PM: Finished saving maven dependencies
3:08:41 PM: Started saving boot dependencies
3:08:41 PM: Finished saving boot dependencies
3:08:41 PM: Started saving go dependencies
3:08:41 PM: Finished saving go dependencies
3:08:41 PM: Build script success
3:08:41 PM: Starting to deploy site from 'public'
3:08:41 PM: Creating deploy tree 
3:08:41 PM: 0 new files to upload
3:08:41 PM: 0 new functions to upload
3:08:41 PM: Post processing done
3:08:41 PM: Site is live
3:09:02 PM: Finished processing build request in **35.378011488s**

Is that good?

That is a build log from some service you are using (netifly?).

Do a local build with:

$ hugo --templateMetrics --templateMetricsHints

Then post the results here if you want help interpreting it.

1 Like

Yes, I’m using Netlify with instant deploy. I’m using it from mobile without any local development.

Yes.

2 Likes