redocly-cli icon indicating copy to clipboard operation
redocly-cli copied to clipboard

redocly CLI preview command significantly slower than legacy preview-docs command

Open fulstadev opened this issue 1 year ago • 30 comments

Describe the bug

I've updated my free redocly CLI version from < 2.0.0 to now 2.0.2. This led to the fact that the API docs generated via the preview command (as the preview-docs command has been abandoned) take a significantly longer time to be generated, like 10 seconds instead of 1. Also, The layout changed from the aspect you see in this screenshot to this.

I've also noted that the build-docs command still generates the docs file in the "old" format, which is apparently no longer available through the preview command (as you can see here), is that normal?

Will this change be reversed / can I somehow revert back to the other layout and generation, or is this change permanent?

fulstadev avatar Aug 05 '25 09:08 fulstadev

The preview command slightly differs from preview-docs as it uses our new Redoc to render OpenAPI docs and Realm for other document types, so the performance difference is expected. The build-docs command will eventually pair with the preview command in using the new Redoc, so if you want to use the older one, you will have to stay on v1. I'm closing the issue since there's no bug. Please let me know if I missed anything.

tatomyr avatar Aug 11 '25 08:08 tatomyr

To confirm, running preview and being required to compile the the JS, e.g. [info] JavaScript compiled dur="484286ms" is not a bug? Shouldn't compiled JS be shipped instead?

scottbusche-usps avatar Aug 11 '25 15:08 scottbusche-usps

484286ms

@scottbusche-usps you mean 8 mins? That's definitely not what I'd expect. Could you confirm it takes that long to start the preview on every run, not just the first one? Is the result better on v1 with the preview command?

tatomyr avatar Aug 11 '25 18:08 tatomyr

It's the first time, with every new version. I never used preview before, always preview-docs.

scottbusche-usps avatar Aug 11 '25 18:08 scottbusche-usps

@scottbusche-usps well, that's because of the difference between those commands. The preview one uses Realm through NPX to render docs, so it has to be kind of installed globally with every new version. However, you can install a specific Realm version in your project's dev dependencies if you want to make the command faster and more predictable.

tatomyr avatar Aug 12 '25 11:08 tatomyr

I tested v1 of preview and it's much faster to start by comparision:

npx -y @redocly/[email protected] preview
npm warn deprecated [email protected]: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
npm warn deprecated [email protected]: Glob versions prior to v9 are no longer supported

Launching preview of Realm enterprise using NPX.

[info] Starting project preview mode.                                                                                                                                                                                                                                                                                                                                       
[info] JavaScript compiled dur="2755ms"
[info] Successfully copied migrations

Note, that npx -y @redocly/[email protected] preview-docs <file> is near instant and I'll go back to using that in the meantime.

scottbusche-usps avatar Aug 12 '25 20:08 scottbusche-usps

npx -y @redocly/[email protected] preview-docs is near instant

Yes, you can still use it with v1 but be aware that it's different from our latest Redoc.

I tested v1 of preview and it's much faster to start by comparision

This is actually strange because there were no changes to the preview command as far as I remember. Are you sure you're comparing apples to apples meaning you're running it with an installed Realm version?

tatomyr avatar Aug 13 '25 05:08 tatomyr

I'm running both through npx as I listed above, I don't have a package.json or anything of the sort.

scottbusche-usps avatar Aug 13 '25 13:08 scottbusche-usps

Sorry, I cannot reproduce anything like that.

@volodymyr-rutskyi maybe you know more about what could be wrong?

tatomyr avatar Aug 13 '25 15:08 tatomyr

No, I can't reproduce this as well. 484286ms is way too long for the js compilation.

@scottbusche-usps What OS do you use? And are there other files in the directory where you run the preview command? Also, if you could share a reproducible example of a project, that could help us get some clues.

volodymyr-rutskyi avatar Aug 14 '25 06:08 volodymyr-rutskyi

The project is a single yaml file, as I'm using the -d command or cd into the directory.

Microsoft Windows [Version 10.0.22621.5624]
node -v
v22.18.0

I am in a VDI environment as well.

scottbusche-usps avatar Aug 14 '25 13:08 scottbusche-usps

On my machine first execution takes ~4mins (JavaScript compiled dur="226499ms") and 2GB of ram Subsequent executions are faster (JavaScript compiled dur="2886ms").

In past I was cancelling the task because I thought that it got stuck

piotr-cz avatar Aug 27 '25 07:08 piotr-cz

@scottbusche-usps @piotr-cz we also observed a slow JS compilation in GitHub Actions on Windows runners and we're looking into it. The problem is not related to this specific GitHub issue nor to the Redocly CLI directly, so I won't reopen it. But we'll notify you when it's fixed in Realm.

volodymyr-rutskyi avatar Aug 27 '25 15:08 volodymyr-rutskyi

Hello, I am trying to migrate a @redocly/cli project using 1.34.5 to 2.1.0 with several API files (redocly.yaml/apis/[name]/root).

Before, I just had to run redocly preview-docs name for local development with live reload. And I can't get the new command to work. Is there no apis parameter? And honestly, I don't understand the product and plan parameters in the documentation...

And what I see in this ticket worries me. Does that mean there's no longer a way to have build-docs with live reload mode?

kekel87 avatar Sep 10 '25 14:09 kekel87

@scottbusche-usps @piotr-cz the fix to JS compilation on Windows was released in Realm version 0.125.2 - now it should only take a couple of seconds even on the first run. The new version should be used by the preview command automatically unless an older version is pinned in the package.json.

volodymyr-rutskyi avatar Sep 15 '25 14:09 volodymyr-rutskyi

@kekel87 in the preview-docs command we used our old product, Reference Docs, which is a part of another legacy API Registry (Workflows) product. The new preview command is a bit different, and uses our new Realm product, which is much more powerful, as it supports much wider range of doc types. In particular, it uses our new Redoc version (which will eventually become the default for the build-docs command). If you prefer to use our old Redoc and set of products, you may still use v1, as we'll be supporting it for some time.

tatomyr avatar Sep 17 '25 06:09 tatomyr

@tatomyr Thank you for your reply. Foes that mean it's no longer part of the free plan? I would just like to know the equivalent of the old command with the new one: redocly preview-docs name It would be good to add a section to your documentation.

kekel87 avatar Sep 17 '25 07:09 kekel87

Foes that mean it's no longer part of the free plan?

@kekel87 what exactly did you use the preview-docs command for? Because some parts will remain free and some become paid.

tatomyr avatar Sep 17 '25 09:09 tatomyr

We use it to render our API documents with live reload while we modify them.

kekel87 avatar Sep 17 '25 10:09 kekel87

You can use the preview command for free too (and it has live reload for local development).

adamaltman avatar Oct 07 '25 15:10 adamaltman