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

speed up livereload #3446

Merged
merged 1 commit into from
Aug 9, 2023
Merged

Conversation

t-fritsch
Copy link
Collaborator

livereload in latest version is a lot slower than in previous versions : one has to wait 1-4s when saving html or md file to see the result in the browser.

This PR aims to get back to instant refresh, as it was in previous versions of Reveal (as on 3.6, 3.9, 4.0).

The reason of the drop in performance is this commit : 8492b82#diff-25789e3ba4c2adf4a68996260eb693a441b4a834c38b76167a120f0b51b969f7R289

gulp.task('reload', () => gulp.src(['**/*.html', '**/*.md'])
    .pipe(connect.reload()));

By passing **/*.html and **/*.md it looks like (I'm no gulp expert) we force gulp to crawl recursively every folder in the project, searching for html or md files. And this makes a lot of files even in the base reveal.js project (node_modules is not excluded 😰).

This crawling seems quite useless because this task is not responsible for the watch, all it does is telling the browser to refresh. Still, the connect.reload() API needs a stream of files to execute (I tried many ways to launch it without gulp.src(...) before with no success).
Since the src stream is irrelevant, I made gulp.src only crawl the original index.html file, and everything works fine : when modifying a file, even if it's not the base index.html file, the browser refreshes instantly, and shows every modifications made.

Here is an approximative bench on my dev computer (macbook pro M1Pro, RAM 32Go), measuring time from file save, to modification shown in browser (may differ from timing showed in terminal) :

  • old config : 1000-3000ms, thousands (!!!) of network request fired from the browser (all cancelled) 😱
  • new config : 10-50ms, no additional network requests 🥳

connect.reload needs a stream of files to fire, but this stream is irrelevant here and slows refresh time a lot (from ~2ms to 2000ms here)
@hakimel hakimel merged commit b8d97d2 into hakimel:master Aug 9, 2023
@hakimel
Copy link
Owner

hakimel commented Aug 9, 2023

This delay has annoyed me for a while now but I was not able to track down the cause. Thanks so much for fixing it 🙌

I tested reloading of html and md files in the root and sub directories and all seems to work perfectly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants