Slow loading editor - mermaid?

When I reload the editor page it often takes 20 seconds or so, which is painful as I am debugging and have to keep restarting. This is running node red on an i5 Ubuntu machine with the browser on the same machine.

When I look at the network tab most things are milliseconds, but I see


and often it is more time than that.
The URL is http://localhost:1880/vendor/mermaid/mermaid.min.js?_=1719418305320 and if I put that in the browser it comes back instantly.
The other large item fetched is http://localhost:1880/nodes?_=1719418305318 which is 1.7MB and takes 94ms, so it does not appear to be a network problem.

I am using NR v4.0.0 but I don't think this is a new issue.

Any suggestions?

Interesting. On my dev PC (W11, i9, 32GB RAM), it is still taking 4 seconds. But the most telling thing is that it is not being cached and that is surely wrong.

Other scripts are cached correctly (return a 304 status as expected.

And the problem is that the cache-buster id on that resource is changing on each load so it can't be cached. Surely a bug?

Plugins also not being cached which may also be wrong? Though that is tiny on my system.

Hmm, yes, that is not ideal.

Have raised mermaid loading using non-standard cache busting · Issue #4810 · node-red/node-red · GitHub to address it.

1 Like

What is also strange:


(with the cache turned off)

Though not the largest resource, it takes far longer than anything else to load:

Not sure why that is. Does the network time column include startup processing time for the library?

The mermaid library is dynamically loaded the first time it's needed - or something like that. Unlike the other libaries that are all loaded as part of loading the editor.

In that case should it even get loaded when I refresh the editor page (without anything open)?

Just checked this, and it is "bizarre"...

More than one refresh.

It real seems that the mermaid library takes a very long time downloading, but the strange part is that there are others "pieces" that are larger and takes lower time.

In the case of the download of the mermaid, wireshark indeed has some big gaps, and complains about some things...

This was in a local network.

Via external server, it also takes quite some time, but other "large" chunks also take their time...

Could it just be that the processor is bogged down loading the flows at the time mermaid is fetched and so the fetch slows down?

Not sure, but here is mermaid loaded direct from JSDelivr in a fairly empty uibuilder page:

    <!-- #region Supporting Scripts. These MUST be in the right order. Note no leading / -->
    <script defer src="https://cdn.jsdelivr.net/npm/mermaid@10.9.1/dist/mermaid.min.js"></script>
    <script defer src="../uibuilder/uibuilder.iife.min.js"></script>
    <script defer src="./index.js">/* OPTIONAL: Put your custom code in that */</script>
    <!-- #endregion -->

Not only is it MUCH smaller, it loads in a reasonable time. Weirdly small.

Installing the mermaid npm package in uibuilder and calling the local version gives this:

<script defer src="../uibuilder/vendor/mermaid/dist/mermaid.min.js"></script>

Which is obviously closer in size but as you can see only requires 50ms.

Just for fun, I also loaded it as a module as recommended in the docs:

From CDN:

Local:

The ESM version is so small because it is just this:

import { b9 } from "./mermaid-dcacb631.js";
export {
  b9 as default
};

Funky stuff!

On the server, i don't so. At least checking the CPU usage via pm2 for the node-red process nothing in particular when loading the editor.

On the browser, yes, according to the task manager (from Edge) the tab goes up to 110~150 in this PC (i7-8550U)

Just did a small test, even using node-red "local" (127.0.0.1) the time that appears on the dev tools is more or less the same...

But Wireshark between the request and the final answer (HTTP/1.1 200) only takes 69ms.

The same download from a raspberrypi (local network), browser says 1.3s wireshark 0.5s.

It seems that the times shown in the devtools includes also some extra processing of the resource and not only the download time

1 Like

I've pushed the fix for the issue. We'll start caching the mermaid library properly with 4.0.2.

1 Like

Having upgraded to 4.0.2 I am still not seeing mermaid being cached. It appears to have a cache-control max-age of 0, which I think says not to cache it.

Just installed 4.0.2.

It is being cached

It continues to take a long time according to the browser console, but that is a browser issue (probably the time it tables to load/parse the file)

I don't think so actually since I tested it on a separate page and whilst it is pretty big, it only took 141ms from CDN! Not the 3.6s it is taking on my beefy dev PC.

And, I'm afraid it isn't caching. While the cache-buster now remains static, it is still showing a response code of 200 meaning that the browser can't cache it locally. I should be seeing a 304 on a reload.

Oops, my bad, I forgot to turn off disabled cache in dev tools!

So it is caching - but it is still taking 3 1/2 seconds to load for some reason. It doesn't do that on simpler web pages.

  • Content Download. The browser is receiving the response, either directly from the network or from a service worker. This value is the total amount of time spent reading the response body. Larger than expected values could indicate a slow network, or that the browser is busy performing other work which delays the response from being read.

Content download for the mermaid library is showing as 4s on my device. To me, the most likely issue is that the page load is processing a bunch of other stuff at the same time. I can't think of another reason this would take so long for Node-RED but not for another page.

Also not sure if this is related:

But it is in a similar place in the call stack as far as I can tell.

It's defenitly something to do with node-red, and the browser / node-red being busy loading other stuff.

According to wireshark, the network request takes a couple of milliseconds

Just tried one thing, to load an empty project (new created project) and the difference is significant

The first three times and the last, are with the default test project I have (it has around 100 nodes and some 7 tabs).

The other loads, are with a new / empty project.

If the sidebar (help, debug, etc..) is hidden (collapsed) it seems to help.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.