swagger-api / swagger-api/swagger-ui

swagger-ui-dist takes an obnoxiously long time to `require()`

Open
#4,502 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

cat: performance type: enhancement
Dominant language
JavaScript
Stars
29k
Forks
9.3k
Avg merge
2d 23h
Merged PRs (30d)
25

Description

Q A
Bug or feature request? bug
Which Swagger/OpenAPI version? any
Which Swagger-UI version? 3.14.0
How did you install Swagger-UI? npm
Which browser & version? n/a
Which operating system? OS/X
Expected Behavior

'swagger-ui-dist' is a package that exports a single function which gives you the name of a directory that you can serve static content from, so I'd expect require('swagger-ui-dist') to be blindingly fast.

For example:

$ time node -e 'require("path"); console.log(path.resolve(__dirname, "."))'

real	0m0.156s
user	0m0.095s
sys	0m0.052s

0.15 second, and that includes a console.log(), which is slow.

Current Behavior
$ time node -e 'require("swagger-ui-dist")'

real	0m1.439s
user	0m1.020s
sys	0m0.221s

1.4 seconds!

Context

This slows down startup of every app that users swagger-ui-dist.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue identifies swagger-ui-dist and its npm require() path, but no source file or test. Start by profiling package startup against the reported Node command and inspect the package entry point. Done means require("swagger-ui-dist") completes substantially faster without changing the package's exported behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
performance, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.