Super slow HMR in meteor 3.0

I think It was there like decade ago but it run in background. Recently we move away from Fiber something changed.

1 Like

I can definitely reproduce the problem. I prepared the repository and compared the rebuild times between Meteor 2 and 3. I also tested by downgrading to 3.0.1 from 3.0.3 to identify any possible regression. But the issue is entirely happening on Meteor 3.0.

This issue lies in the core. There is an extra process that takes longer than expected or waits unnecessarily. We’ll need to debug the core using this app to identify it. We have noted the details and will investigate further.

6 Likes

Great to hear that you‘ll have a look at this, thanks.

That repo is from one of my students. I’ll let her know that her impatience while waiting for changes in her project contributed to solving this issue :wink:

5 Likes

By the way, is there a way to pick up the HMR state somehow to display sort of a loading indicator in dev mode in the browser?

That’s a good question, I just included a little debugging helper for my side which shows random emoji depending on the latest build time completion:

            // Let's fetch the current unique app version which should be changed for each HCP.
            // We'll always use the latest _cordova_ version info so we can compare the "emoji key"
            // between desktop and cordova versions when trying to figure out whether our cordova
            // version has the latest code. Most times both versions should change at the same time when
            // we edit the client code.
            const i = this.setInterval(() => {
                let versionHmr = Autoupdate._clientVersions?._versions?.get('web.cordova')?.versionHmr
                if (!versionHmr) return
                // We got the current version number now, it takes a bit after a refresh to arrive.
                // We use this to seed the random number generator and let it pick a few emoji to visualize the current
                // app "version".
                //
                // The nice thing is that it's a number already (last update timestamp I think)
                Srand.seed(versionHmr)
                const emojiArr = [...emojiString]
                console.log({emojiArr})
                const emoji = `` + Srand.choice(emojiArr) + Srand.choice(emojiArr) + Srand.choice(emojiArr)
                this.state.currentVersionEmojiKey = emoji
                clearInterval(i)
            }, 100)

This is incomplete, you need to provide it with a string of emojis like this: “:pancakes::unamused::weight_lifting_man::sun_behind_large_cloud:” or whatever you like (but put a few dozen in at least).

And you need to install the Srand package if you want the emoji :slight_smile:

But you can see where I pick up the latest build time here:

Autoupdate._clientVersions?._versions?.get('web.cordova')?.versionHmr

→ i’m not sure what of Autoupdate is reactive, if anything, but maybe it’s a good direction to poke at.

1 Like

@nachocodoner Is there already an issue on github associated to this?

No that I’m aware of.

Would you like to create one?

Ok, did that right here HMR Slowness with Meteor 3.0.3 + React + MUI6 · Issue #13430 · meteor/meteor · GitHub

4 Likes

I want to update that after some research, I believe I found the fix. I still need to verify it with the example app provided. I will do this next.

More details are available on the PR. Hopefully, we can include it in the next version.

4 Likes

Hi @nachocodoner, the beta of 3.1 has it fixed. I tested and in development changes are instantly reflected in the browser.

(also copying @leonardoventurini )

2 Likes

I’d also like to try this, how can I use 3.1?

Strange, since these changes appeared after the 3.1 beta release. I can’t think of another change in the 3.1 beta that could have affected the build.

Alternatively, there might have been an issue with the record package usage, as @minhna reported, which was fixed automatically on the server status when you tested it. In my debugging, I didn’t notice any major changes in the package recording, but I did find other slowdowns in the build itself, which seem to be a negative impact and provided a fix already. I’ll review the recordPackageUsage to see if it’s affecting the rebuild flow under poor network conditions.

But definitely any of these changes would be available on the next beta or release.

Ok, I will update my largest project now and get back soon.

Ok, with this: Super slow HMR in meteor 3.0 - #8 by minhna, it takes less than a second (which I’d call instantly).

After removing that record from hosts, it takes between 1 and 3 seconds. I mean sometimes 1 sometimes 3

1 Like

Recording packages stats definitely caused slowdowns, included this fix as well as part of the set of changes for next release.

2 Likes

We’ve released a new RC version of Meteor 3.1, including the fixes noted here and in the PR.

meteor update --release 3.1-rc.0

If you can test it, please do and share your feedback.

1 Like

Tested and as we say in engineering … 60% of the time works every time :slight_smile:
Looks good, I would consider it fixed.

2 Likes

Official Meteor 3.1 has been released, including the fix mentioned in this thread.

Update your app and share any feedback.

meteor update --release 3.1
2 Likes

That definitely brought back speed, thanks for including this.

After updating to 3.1 I am still getting about 10 second rebuild time. My project is pretty complicated, but I would love to be able to dive in and figure out what is actually causing the problem.

Is there any suggestions on how to debug further

| 
| Top leaves:
| Babel.compile............................................5,147 ms (1085)
| jsAnalyze.parse..........................................2,163 ms (1044)
| other ImportScanner#resolve................................779 ms (15803)
| other ImportScanner#realPath...............................506 ms (6455)
| getPrelinkedFiles toStringWithSourceMap....................506 ms (1)
| ImportScanner#readFile.....................................264 ms (2604)
| sha512.....................................................249 ms (5260)
| files.readdirWithTypes.....................................243 ms (1356)
| sha1.......................................................189 ms (15132)
| findImportedModuleIdentifiersVisitor.......................163 ms (1044)
| files.writeFile............................................119 ms (6)
| 
| (#5) Total: 11,375 ms (Rebuild App)
| 

This is after changing just one file, which should be fast.

Note, this is about half the time it used to take, so there are definitely improvements, but in general I’m at a loss on how to dive deeper into it.