ZORALab / Hestia

One Peaceful Frontend+Backend Software Library Suite.
https://hestia.zoralab.com
Other
19 stars 1 forks source link

Improve Hugo's Iterative Performance #59

Closed hollowaykeanho closed 1 year ago

hollowaykeanho commented 1 year ago

Description

Please provide a short description of what feature you're looking forward to
enhance below. Please include the story behind your idea as well to give a
better visualization of your idea.

The engine is getting slower again. Need to look through what exactly is slowing the system down. Symptom is not seen on newly deployed project.

Consider the following optimizations direction:

Expected Behavior

Please specify the expected behavior of your requested enhancement. Some great
and helpful pointers are your expected interface (e.g. command patterns,
simple sketches of the user interface, etc).

Keep it to less than 10000ms at large volumes.

Current Behavior

Please specify the current behavior (e.g. workaround, blockage, etc).

Right now, it took too long for an iterative improvement.

u0:docs$ ./server.cmd 
Start building sites … 
hugo v0.109.0-47b12b83e636224e5e601813ff3e6790c191e371 linux/amd64 BuildDate=2022-12-23T10:38:11Z VendorInfo=gohugoio

                   | EN   
-------------------+------
  Pages            |  69  
  Paginator pages  |   0  
  Non-page files   | 702  
  Static files     |  70  
  Processed images |  27  
  Aliases          |   0  
  Sitemaps         |   0  
  Cleaned          |   0  

Built in 101171 ms
Watching for changes in /home/u0/Documents/zoralab/Hestia/{archives,docs,hestiaHUGO}
Watching for config changes in /home/u0/Documents/zoralab/Hestia/docs/config/_default, /home/u0/Documents/zoralab/Hestia/hestiaHUGO/config/_default
Environment: "development"
Serving pages from memory
Web Server is available at http://localhost:8080/ (bind address localhost)
Press Ctrl+C to stop

Change detected, rebuilding site.
2023-02-05 10:17:05.194 +0800
Template changed WRITE         "/home/u0/Documents/zoralab/Hestia/docs/layouts/partials/landing/hugo/business_en.html"
Total in 100389 ms

Attachment

Please drag and drop the necessary data files (e.g. screenshot, logs, etc)
below.
hollowaykeanho commented 1 year ago

Independent results:

u0:sites$ ./server.cmd 
Start building sites … 
hugo v0.107.0-2221b5b30a285d01220a26a82305906ad3291880 linux/amd64 BuildDate=2022-11-24T13:59:45Z VendorInfo=gohugoio

                   | EN   
-------------------+------
  Pages            |  20  
  Paginator pages  |   0  
  Non-page files   | 333  
  Static files     | 157  
  Processed images |  27  
  Aliases          |   0  
  Sitemaps         |   0  
  Cleaned          |   0  

Built in 38732 ms
Watching for changes in /.../sites/{assets,content,data,layouts,static,themes}
Watching for config changes in /.../sites/config/_default
Environment: "development"
Serving pages from memory
Web Server is available at http://localhost:8080/ (bind address localhost)
Press Ctrl+C to stop

Change detected, rebuilding site.
2023-02-16 06:27:28.881 +0800
Source changed WRITE         "/.../researches/2021-06-11-image-web-user-interface-architectural-design-analysis/__page.toml"
Total in 27102 ms

Change detected, rebuilding site.
2023-02-16 06:27:56.381 +0800
Source changed WRITE         "/.../researches/2021-06-11-image-web-user-interface-architectural-design-analysis/__page.toml"
Total in 31589 ms

Change detected, rebuilding site.
2023-02-16 06:29:26.881 +0800
Source changed RENAME        "/.../researches/2021-06-11-image-web-user-interface-architectural-design-analysis/__data.toml"
Total in 30810 ms
hollowaykeanho commented 1 year ago

Appearently, reducing the # of partials in the libraries increases the performances dramatically.

Suspect we have an ioctl storm here when the sites is too big at scale.

hollowaykeanho commented 1 year ago

New discovery found to counter the IOCTL storm by using native Go's define and template functions instead of the current partial. Then, we can stuff it into a single Library partial file and wrap it with a single partialCached to dramatically speed things up.

Hestia only needs to load its entire libraries once from 1 single index file like Hestia/functions/data/Page. The only downside here is HestiaHUGO library developer has to constantly restart the server in order to flush those Cached at every changes.


Code snippet:

{{- define "Hestia::test" -}}
        {{- $v := add .Input 1 -}}
        {{- warnf "Successfully called Hestia::test = %v" $v -}}
        {{- .Output.Set "Value" $v -}}
{{- end }}
{{- $s := newScratch -}}
{{- template "Hestia::test" (merge . (dict "Output" $s "Input" 1)) -}}
{{- template "Hestia::test" (merge . (dict "Output" $s "Input" 5)) -}}
{{- warnf "S got: %v\n" ($s.Get "Value") -}}

This yields:

WARN 2023/02/28 19:50:27 Successfully called Hestia::test = 2
WARN 2023/02/28 19:50:27 Successfully called Hestia::test = 6
WARN 2023/02/28 19:50:27 S got: 6

where $s is 6 instead of unset or 2.

corygalyna commented 1 year ago

@hollowaykeanho , please stick to the plan. This change is huge and very risky. It can potentiality crash a lot of things and takes up a lot of resources to implement. The marketing work has to be ready first.

You can do it before continuing Phase 2. In fact, I can see we can align the function calls with hestiaLIB (e.g. hestiaSTRING.TrimLeft).

hollowaykeanho commented 1 year ago

Well aware. I think we found our last piece of puzzle.

corygalyna commented 1 year ago

I had opened Phase 1.2 in the project initialisation plan just for this upgrade. You can do it AFTER the marketing segment is done and ready to be shared across Hugo communities.

corygalyna commented 1 year ago

Since this is heavily influencing the writing of getting started (Issue #67), please see it done before continue writing the them.

corygalyna commented 1 year ago

@hollowaykeanho , I think let's use the the existing one instead of template that we discovered earlier for compatibility. I have a strong feeling that support for Hugo shall be removed somewhere in the near future due to their internal operating limitations.

Let's patch the newly discovered string processor to the existing one and observe the performance gain.. then reduce the partial inter-dependency calls to the minimum.

We have to catch the schedule back after deploying Hestia for our official company website.

hollowaykeanho commented 1 year ago

I share the same thought. After upgrading the company's website, there is much time left. However, Hestia gained quite a lot of improvements compared to the past Bissetii: it only takes 1 month to consolidate 3 repositories into 1.

hollowaykeanho commented 1 year ago

Also, new discovery found that template will not be transferred into the resources. My speculation is the context weren't transferred over and the hugo team decided to invent the partial API instead. I agree with you, let's fix the string first and benchmark for improvements. Forget about the template.

Once we arrived at Phase 3, perhaps we will write a new content compiler based on the current finding.

hollowaykeanho commented 1 year ago

Begin benchmark - empty repo

Start building sites … 
hugo v0.110.0-e32a493b7826d02763c3b79623952e625402b168 linux/amd64 BuildDate=2023-01-17T12:16:09Z VendorInfo=gohugoio
                   | EN   
-------------------+------
  Pages            |   1  
  Paginator pages  |   0  
  Non-page files   | 201  
  Static files     |  62  
  Processed images |  27  
  Aliases          |   0  
  Sitemaps         |   0  
  Cleaned          |   0  

Built in 31724 ms
Watching for changes in /home/u0/Documents/zoralab/Hestia/{hestiaHUGO,test}
Watching for config changes in /home/u0/Documents/zoralab/Hestia/test/config/_default, /home/u0/Documents/zoralab/Hestia/hestiaHUGO/config/_default                                                     
Environment: "development"                                                                          
Serving pages from memory                                                                           
Web Server is available at http://localhost:8080/ (bind address localhost)                          
Press Ctrl+C to stop    

31 seconds is too long.

hollowaykeanho commented 1 year ago

Applied first improvement iteration: 06b3002f702d6ef8ce5e045b5179fe8949727d0c

Achieved

u0:test$ ./server.cmd 
Start building sites … 
hugo v0.110.0-e32a493b7826d02763c3b79623952e625402b168 linux/amd64 BuildDate=2023-01-17T12:16:09Z VendorInfo=gohugoio

                   | EN   
-------------------+------
  Pages            |   1  
  Paginator pages  |   0  
  Non-page files   | 201  
  Static files     |  62  
  Processed images |  27  
  Aliases          |   0  
  Sitemaps         |   0  
  Cleaned          |   0  

Built in 1299 ms
Watching for changes in /home/u0/Documents/zoralab/Hestia/{hestiaHUGO,test}
Watching for config changes in /home/u0/Documents/zoralab/Hestia/test/config/_default, /home/u0/Documents/zoralab/Hestia/hestiaHUGO/config/_default
Environment: "development"
Serving pages from memory
Web Server is available at http://localhost:8080/ (bind address localhost)
Press Ctrl+C to stop

-30 seconds improvement.

Proceed to purge scan all directories for offline caches pressuring landing page to have long rendering time.

corygalyna commented 1 year ago

I think you hit the sweet spot. Let's try to upgrade the entire documentations and see we can go beyond the current 120 pages limitations.

hollowaykeanho commented 1 year ago

Page data structure construction algorithm optimized. Further reduced to:

Start building sites … 
hugo v0.110.0-e32a493b7826d02763c3b79623952e625402b168 linux/amd64 BuildDate=2023-01-17T12:16:09Z VendorInfo=gohugoio

                   | EN   
-------------------+------
  Pages            |   1  
  Paginator pages  |   0  
  Non-page files   | 201  
  Static files     |  62  
  Processed images |  27  
  Aliases          |   0  
  Sitemaps         |   0  
  Cleaned          |   0  

Built in 1288 ms
Watching for changes in /home/u0/Documents/zoralab/Hestia/{hestiaHUGO,test}
Watching for config changes in /home/u0/Documents/zoralab/Hestia/test/config/_default, /home/u0/Documents/zoralab/Hestia/hestiaHUGO/config/_default
Environment: "development"
Serving pages from memory
Web Server is available at http://localhost:8080/ (bind address localhost)
Press Ctrl+C to stop
hollowaykeanho commented 1 year ago

Corrected most settings, latest speed:

u0:sites$ ./server.cmd 
Start building sites … 
hugo v0.110.0-e32a493b7826d02763c3b79623952e625402b168 linux/amd64 BuildDate=2023-01-17T12:16:09Z VendorInfo=gohugoio

                   | EN  
-------------------+-----
  Pages            |  1  
  Paginator pages  |  0  
  Non-page files   |  0  
  Static files     | 19  
  Processed images | 27  
  Aliases          |  0  
  Sitemaps         |  0  
  Cleaned          |  0  

Built in 788 ms
Watching for changes in /home/u0/Documents/zoralab/Hestia/{hestiaHUGO,sites}
Watching for config changes in /home/u0/Documents/zoralab/Hestia/sites/config/_default, /home/u0/Documents/zoralab/Hestia/sites/config/development, /home/u0/Documents/zoralab/Hestia/hestiaHUGO/config/_default, /home/u0/Documents/zoralab/Hestia/hestiaHUGO/config/development
Environment: "development"
Serving pages from memory
Web Server is available at http://localhost:8080/ (bind address 127.0.0.1)
Press Ctrl+C to stop
hollowaykeanho commented 1 year ago

Too bad the entire existing documentation have to be reconstructed due to new API implementations. =(

corygalyna commented 1 year ago

Built in 788 ms

You're insane.

Too bad the entire existing documentation have to be reconstructed

Worth it. At least with this upgrade, it's way sell-able to the public now.

hollowaykeanho commented 1 year ago

Consolidated CSS+JS processing into single Assets pipeline. Timing increase a bit:

u0:sites$ ./server.cmd 
Start building sites … 
hugo v0.110.0-e32a493b7826d02763c3b79623952e625402b168 linux/amd64 BuildDate=2023-01-17T12:16:09Z VendorInfo=gohugoio

                   | EN  
-------------------+-----
  Pages            |  1  
  Paginator pages  |  0  
  Non-page files   | 18  
  Static files     | 19  
  Processed images | 27  
  Aliases          |  0  
  Sitemaps         |  0  
  Cleaned          |  0  

Built in 949 ms
Watching for changes in /home/u0/Documents/zoralab/Hestia/{hestiaHUGO,sites}
Watching for config changes in /home/u0/Documents/zoralab/Hestia/sites/config/_default, /home/u0/Documents/zoralab/Hestia/sites/config/development, /home/u0/Documents/zoralab/Hestia/hestiaHUGO/config/_default, /home/u0/Documents/zoralab/Hestia/hestiaHUGO/config/development
Environment: "development"
Serving pages from memory
Web Server is available at http://localhost:8080/ (bind address 127.0.0.1)
Press Ctrl+C to stop
hollowaykeanho commented 1 year ago

Implemented global persistent memory storage for caches. This eliminates unnecessary full repo scan on rebuild. The scan only works once on boot. Commit: c073c019184b8e29908b3770444feebd43c5bea6.

The latest results:

u0:sites$ ./server.cmd 
Start building sites … 
hugo v0.110.0-e32a493b7826d02763c3b79623952e625402b168 linux/amd64 BuildDate=2023-01-17T12:16:09Z VendorInfo=gohugoio

                   | EN  
-------------------+-----
  Pages            |  1  
  Paginator pages  |  0  
  Non-page files   | 16  
  Static files     | 19  
  Processed images | 27  
  Aliases          |  0  
  Sitemaps         |  0  
  Cleaned          |  0  

Built in 920 ms
Watching for changes in /home/u0/Documents/zoralab/Hestia/{hestiaHUGO,sites}
Watching for config changes in /home/u0/Documents/zoralab/Hestia/sites/config/_default, /home/u0/Documents/zoralab/Hestia/sites/config/development, /home/u0/Documents/zoralab/Hestia/hestiaHUGO/config/_default, /home/u0/Documents/zoralab/Hestia/hestiaHUGO/config/development
Environment: "development"
Serving pages from memory
Web Server is available at http://localhost:8080/ (bind address 127.0.0.1)
Press Ctrl+C to stop

Change detected, rebuilding site.
2023-04-24 11:10:54.927 +0800
Template added WRITE         "/home/u0/Documents/zoralab/Hestia/hestiaHUGO/layouts/partials/Hestia/functions/data/hugo/parse/BootUp/Init"
Total in 739 ms
corygalyna commented 1 year ago

So we now have 2 states right? Boot and active?

hollowaykeanho commented 1 year ago

yeap. Still working on transient update for those data structures using the caches method.

hollowaykeanho commented 1 year ago

Ok. Rendering functions all optimized. Will port all documentations tomorrow for testing and to certify this task's completion status.

u0:sites$ ./server.cmd 
Start building sites … 
hugo v0.110.0-e32a493b7826d02763c3b79623952e625402b168 linux/amd64 BuildDate=2023-01-17T12:16:09Z VendorInfo=gohugoio

                   | EN  
-------------------+-----
  Pages            |  1  
  Paginator pages  |  0  
  Non-page files   | 16  
  Static files     | 19  
  Processed images | 27  
  Aliases          |  0  
  Sitemaps         |  0  
  Cleaned          |  0  

Built in 866 ms
Watching for changes in /home/u0/Documents/zoralab/Hestia/{hestiaHUGO,sites}
Watching for config changes in /home/u0/Documents/zoralab/Hestia/sites/config/_default, /home/u0/Documents/zoralab/Hestia/sites/config/development, /home/u0/Documents/zoralab/Hestia/hestiaHUGO/config/_default, /home/u0/Documents/zoralab/Hestia/hestiaHUGO/config/development
Environment: "development"
Serving pages from memory
Web Server is available at http://localhost:8080/ (bind address 127.0.0.1)
Press Ctrl+C to stop

Change detected, rebuilding site.
2023-04-24 16:02:43.779 +0800
Source changed WRITE         "/home/u0/Documents/zoralab/Hestia/sites/content/__content.hestiaHTML"
Total in 757 ms
hollowaykeanho commented 1 year ago

@GalynaCory , I will be translating the page to double its page weights and proper i18n implementations. That way, in case anyone is referencing the codes, they have a proper one that we practice.

corygalyna commented 1 year ago

Ok. but in case we hit another performance limiter, remove the 2nd language. I'm optimistic that you had resolved this limitation already.

hollowaykeanho commented 1 year ago

All contributors data ported.

hollowaykeanho commented 1 year ago

All supported programming languages data ported.

hollowaykeanho commented 1 year ago

Optimized hugo data processor ciritical path in cd4f4cb0af65afb5210bfb8043f7e532b3688e8c

hollowaykeanho commented 1 year ago

After all optimizations, final results:

u0:test./server.cmd 
Start building sites … 
hugo v0.111.3-5d4eb5154e1fed125ca8e9b5a0315c4180dab192 linux/amd64 BuildDate=2023-03-12T11:40:50Z VendorInfo=gohugoio

                   | EN  
-------------------+-----
  Pages            |  1  
  Paginator pages  |  0  
  Non-page files   |  0  
  Static files     | 20  
  Processed images | 27  
  Aliases          |  0  
  Sitemaps         |  0  
  Cleaned          |  0  

Built in 1919 ms
Watching for changes in /home/u0/Documents/zoralab/Hestia/hestiaHUGO/{archetypes,assets,data,fonts,layouts,static}
Watching for config changes in /home/u0/Documents/zoralab/Hestia/test/config/_default, /home/u0/Documents/zoralab/Hestia/test/config/development, /home/u0/Documents/zoralab/Hestia/hestiaHUGO/config/_default, /home/u0/Documents/zoralab/Hestia/hestiaHUGO/config/development
Environment: "development"
Serving pages from memory
Web Server is available at http://localhost:8080/ (bind address 127.0.0.1)
Press Ctrl+C to stop

Change detected, rebuilding site.
2023-05-05 17:03:36.412 +0800
Template added WRITE         "/home/u0/Documents/zoralab/Hestia/hestiaHUGO/layouts/partials/Hestia/start"
Total in 1744 ms

on clean boot. Acceptable at least with that much of features.

corygalyna commented 1 year ago

I think we 're good already. I noticed you also fixed a bunch of terrible overheads like 9728ad7f5eded85b80979674ffc28dcd44d35551, 5677de8a09f327f798c99ad71078d048e8b20666, cd4f4cb0af65afb5210bfb8043f7e532b3688e8c, c4ba937496f49e5e74b5b3f1f13a40ddb6f36b72, and abfed3ac34b5e8f8839711ae79e19f7981ff1713.

As far as I can tell, it's good enough already maintaining same level of timing on boot. It's time to port the pages entirely to see the load performance. Finger-cross all these will work well.

hollowaykeanho commented 1 year ago

RobotsTXT data path optimized in 1ed50e6d3d15faf307352995d5ed489a29a1e0fe

hollowaykeanho commented 1 year ago

Decided to remove all directories scanning once and for all in this commit a89d364bf593de34bb356e3ec096c28a9def2dcd.

The automatic caching is good enough to cache the entire pages. If user wants some assets to be cached. He/she can add the data file in data/Hestia/Caches/ directory for guarenteed caches.

hollowaykeanho commented 1 year ago

@corygalyna , I think you'll love this. Commit: d0669247fbda3ce2b2fbb10bdd687df6cb0d8fb1

u0:sites$ ./server.cmd 
Start building sites … 
hugo v0.111.3-5d4eb5154e1fed125ca8e9b5a0315c4180dab192 linux/amd64 BuildDate=2023-03-12T11:40:50Z VendorInfo=gohugoio

                   | EN   
-------------------+------
  Pages            |   3  
  Paginator pages  |   0  
  Non-page files   |  54  
  Static files     | 453  
  Processed images |  27  
  Aliases          |   0  
  Sitemaps         |   0  
  Cleaned          |   0  

Built in 3248 ms
Watching for changes in /home/u0/Documents/zoralab/Hestia/{hestiaHUGO,sites}
Watching for config changes in /home/u0/Documents/zoralab/Hestia/sites/config/_default, /home/u0/Documents/zoralab/Hestia/sites/config/development, /home/u0/Documents/zoralab/Hestia/hestiaHUGO/config/_default, /home/u0/Documents/zoralab/Hestia/hestiaHUGO/config/development
Environment: "development"
Serving pages from memory
Web Server is available at http://localhost:8080/ (bind address 127.0.0.1)
Press Ctrl+C to stop

Change detected, rebuilding site.
2023-05-17 19:00:25.184 +0800
Template added WRITE         "/home/u0/Documents/zoralab/Hestia/hestiaHUGO/layouts/partials/hestiaCOMPILERS/hestiaHUGO/sanitizePWAData"
Total in 2753 ms

3 pages, no more delay, and also solved #79 as well. I'm confident we had completed this task as we originally intended after dropping Rust as stated in #104.

This should dramatically speeds up the documentation porting as Hugo, Go, and TinyGo are very aligned together.

corygalyna commented 1 year ago

Perfect. Proceed to port the documents.

corygalyna commented 1 year ago

I see you have ported quite a lot of pages... performance so far?

hollowaykeanho commented 1 year ago
Start building sites … 
hugo v0.111.3-5d4eb5154e1fed125ca8e9b5a0315c4180dab192 linux/amd64 BuildDate=2023-03-12T11:40:50Z VendorInfo=gohugoio

                   | EN   
-------------------+------
  Pages            |   6  
  Paginator pages  |   0  
  Non-page files   |  97  
  Static files     | 574  
  Processed images |  27  
  Aliases          |   0  
  Sitemaps         |   0  
  Cleaned          |   0  

Built in 6503 ms
Watching for changes in /home/u0/Documents/zoralab/Hestia/{hestiaHUGO,sites}
Watching for config changes in /home/u0/Documents/zoralab/Hestia/sites/config/_default, /home/u0/Documents/zoralab/Hestia/sites/config/development, /home/u0/Documents/zoralab/Hestia/hestiaHUGO/config/_default, /home/u0/Documents/zoralab/Hestia/hestiaHUGO/config/development
Environment: "development"
Serving pages from memory
Web Server is available at http://localhost:8080/ (bind address 127.0.0.1)
Press Ctrl+C to stop

Change detected, rebuilding site.
2023-05-22 17:58:41.378 +0800
Source changed WRITE         "/home/u0/Documents/zoralab/Hestia/sites/content/en/licenses/__i18n.toml"
Total in 6594 ms

Done landing page, 404 page.

Porting licenses page at the moment.

corygalyna commented 1 year ago

Thanks for the high-tier badges. I think we need 1 more week to complete the porting. So far the results are very good.

hollowaykeanho commented 1 year ago

Been non-stop working on it.

hollowaykeanho commented 1 year ago

all /getting-started documents fully ported. Translating now...

hollowaykeanho commented 1 year ago

Release catalog ported and translated (/en/releases/ & /zh-hans/releases/) .

hollowaykeanho commented 1 year ago

/en/releases/v1p0p0 and /zh-hans/releases/v1p0p0 ported.

hollowaykeanho commented 1 year ago

/en/releases/v1p1p0 and /zh-hans/releases/v1p1p0 ported.

hollowaykeanho commented 1 year ago

/en/specs/ and /zh-hans/specs/ redesigned and ported.

hollowaykeanho commented 1 year ago

/en/specs/hestiaGUI and /zh-hans/specs/hestiaGUI redesigned and ported.

hollowaykeanho commented 1 year ago

/en/specs/hestiaGUI/zoralabCODE and /zh-hans/specs/hestiaGUI/zoralabCODE redesigned and ported.

hollowaykeanho commented 1 year ago

/en/specs/hestiaGUI/zoralabPRE and /zh-hans/specs/hestiaGUI/zoralabPRE redesigned and ported.

hollowaykeanho commented 1 year ago

/en/specs/hestiaGUI/zoralabBLOCKQUOTE and /zh-hans/specs/hestiaGUI/zoralabBLOCKQUOTE redesigned and ported.

hollowaykeanho commented 1 year ago

/en/specs/hestiaGUI/zoralabULIST and /zh-hans/specs/hestiaGUI/zoralabULIST redesigned and ported.

hollowaykeanho commented 1 year ago

/en/specs/hestiaGUI/zoralabOLIST and /zh-hans/specs/hestiaGUI/zoralabOLIST redesigned and ported.

hollowaykeanho commented 1 year ago

/en/specs/hestiaGUI/zoralabTOC and /zh-hans/specs/hestiaGUI/zoralabTOC redesigned and ported.

corygalyna commented 1 year ago

That's some frequency. How many left?