Generation of the Swagger page takes too long...

2,911 views
Skip to first unread message

Henrik Helmø Larsen

unread,
Jun 29, 2016, 6:14:10 AM6/29/16
to Swagger
I think this question has been asked before: is there any way to speed up the generation of the Swagger-UI page?
The page loads quite quickly (within a sec or two). But "fetching the resource list..." (generating the JSON file) seems to take 10-15 sec. After that the rendering of the page takes another 2-3 sec.
The result is >20 sec to get the API docs... I find that too long. I know it has to traverse my code and I have quite a lot of endPoints - maybe there are some tricks to speed up the process...

The page is located here:

Henrik Helmø Larsen

unread,
Jun 29, 2016, 7:25:16 AM6/29/16
to Swagger
Btw - I use Swagger 1.5.8 (I know there is a 1.5.9) - if this solves the problem I will gladly upgrade...

Ron Ratovsky

unread,
Jun 29, 2016, 9:58:38 AM6/29/16
to swagger-sw...@googlegroups.com

Hi Henrik,

 

Looking at the page you shared, it looks like there are two main things that cause the slowness.

The first – your spec is fairly large – around 1MB – the spec is not generated each time so it’s really just a download speed effect there. Not much can be down about it.

The second – the validator is also taking long – this again due to the size of the file. You can try to disable the validator by setting the validatorUrl to null – see https://github.com/swagger-api/swagger-ui#parameters.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Henrik Helmø Larsen

unread,
Jun 29, 2016, 2:57:11 PM6/29/16
to Swagger
Thank you Ron.

The connection I am on is 100+MByte synchronous så I doubt that is a bottleneck ;-)
I will try your suggestion with disabling the Validator.

tony tam

unread,
Jun 29, 2016, 3:05:48 PM6/29/16
to swagger-sw...@googlegroups.com
Well your spec is delivered pretty slowly (almost 4 seconds is network):

real 0m3.726s
user 0m0.038s
sys 0m0.033s

However, running locally isn’t great either:



Try the latest master to see if that helps and report back?

Henrik Helmø Larsen

unread,
Jun 30, 2016, 5:33:27 AM6/30/16
to Swagger
Thank you both of you.

I have now updated to version 1.5.9 - though I didn't see any big time improvements :-( (But I guess this is only relevant on first request to the JSON file as it will not be generated again until a restart of the service...)

I have turned off validation (validateURL: null). This seems to have helped a little.

The page still takes >10 sec to display (in Chrome 51), a little quicker in FireFox 45 (about 9sec) but almost 1 min!!! on Edge (ver 25?) browser :-(

I have checked delivery times - it seems to deliver the JSON file quite quickly (1-2 sec) - here is 5 runs on my machine:
C:\Users\HHL\Downloads\curl-7.49.1-win64-mingw\bin>curl https://test-api.cochrane.org/swagger.json >swagger.json
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current  Dload  Upload   Total   Spent    Left  Speed
100 1062k    0 1062k    0     0   526k      0 --:--:--  0:00:02 --:--:--  526k

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current  Dload  Upload   Total   Spent    Left  Speed
100 1062k    0 1062k    0     0   781k      0 --:--:--  0:00:01 --:--:--  781k

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current  Dload  Upload   Total   Spent    Left  Speed
100 1062k    0 1062k    0     0   531k      0 --:--:--  0:00:02 --:--:--  531k

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current  Dload  Upload   Total   Spent    Left  Speed
100 1062k    0 1062k    0     0   601k      0 --:--:--  0:00:01 --:--:--  601k

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current  Dload  Upload   Total   Spent    Left  Speed
100 1062k    0 1062k    0     0   514k      0 --:--:--  0:00:02 --:--:--  514k

The time seems to be spent parsing the JSON file on the client side. Is there any way (or future plan) to "only" parse and generate the top level information on the Swagger documentation page (what is displayed when opening the page)? It seems to generate everything - also things that are not yet visible. Maybe an idea could be to parse only what is visible. Of course this would cause a longer processing time when opening endPoint-documentation - but that would distribute the time instead of using all parsing time on the opening of the page...? Once an endPoint-section is generated - it doesn't need to be generated again (on the same client) if the endPoint is closed and reopened...

Maybe I have misunderstood and this is what you do already?

/Henrik

Henrik Helmø Larsen

unread,
Jul 6, 2016, 4:17:27 AM7/6/16
to Swagger
@Ron and @tony tam - could you comment on the >1 min it takes to load the page in Edge. Do you experience the same problem? Please also let me know if "optimizing" the page like I described in the bottom of the mail is what Swagger currently does - or if there is any plan to do it like described?

BW,
Henrik

tony tam

unread,
Jul 7, 2016, 12:55:06 PM7/7/16
to swagger-sw...@googlegroups.com
Hi, there are two main steps in rendering the UI.

First, reading and interpreting the swagger definition.  That is handled by swagger-js (which is packed into the swagger-ui.js).  If you see slowness there, it is typically easy to address.  There are some situations with very complicated remote references that can slow it down—you’d need to look at the profile data in your browser to determine this, or put in some timers in the code manually.

The second speed issue may be in rendering.  The rendering depends a lot on what is in your definition.  For example, we use a markdown renderer for descriptions.  If you don’t use markdown, you can disable that and it will definitely speed things up.  Also we use something called highlight.js to render and highlight models and sample JSON.  if you have a lot of models, that can slow it down. I suggest trying  to disable that aspect as well for testing.

Reply all
Reply to author
Forward
0 new messages