Skip to content

Lazy load model properties #4280

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
heldersepu opened this issue Mar 2, 2018 · 4 comments
Open

Lazy load model properties #4280

heldersepu opened this issue Mar 2, 2018 · 4 comments

Comments

@heldersepu
Copy link
Contributor

heldersepu commented Mar 2, 2018

Q A
Bug or feature request? Performance Bug
Which Swagger/OpenAPI version? 2.0
Which Swagger-UI version? 3.11
How did you install Swagger-UI? PetStore
Which browser & version? Chrome
Which operating system? Win 10

Demonstration API definition

petstore.swagger.io/...&url=https://heldersepu.github.io/hs-scripts/swagger/4248_swagger.json

Expected Behavior

Fast expansion of model properties

Current Behavior

Very slow expansion of model properties

Possible Solution

Lazy load model properties like we do the models

Context

Looking at the current implementation, the collapsed models show right away (big thanks 2 @shockey)

Expanding small models is quick, but the largest models (such as Patrimonio ) takes quite a while, once it fully expands, expanding child models takes no time...
I believe that is because we are loading the entire tree of the model.

@shockey
Copy link
Contributor

shockey commented Mar 2, 2018

I think the best approach for this is to add a depth option to the subtree resolver, which would limit how many levels of $refs are resolved.

For example, depth: 1 would prevent resolution of any data that was placed as a result of an earlier resolution cycle.

This will be challenging: Swagger-Client will need some reworking in order to keep up with depth (we can't encode that metadata into the definition as we go, since that data may be used as base data for a later call to the resolver), and Swagger-UI will need to be able to tell when a subtree needs further resolution (currently it just checks to see if data for a given path exists at all).

@naren19

This comment has been minimized.

@bestmike007
Copy link
Contributor

Profiling the expanding action:

image

Rendering the whole model property tree takes half of the time; and converting the model tree to an immutable map takes the other half.

Profiling the folding action:

image

It's worth mentioning that, lazy loading model properties should only delay the performance degradation, because the more properties loaded the less it could be efficient and fluent.

Storing the spec with a plain json object in the state can avoid the conversion; but is error-prone without enforcing a code convention and code review. And it also requires a lot of changes to the existing code.

Is it possible to delay the subtree resolving process to the render function? Other than lazy loading, delay resolving also improves the performance. Resolving includes:

  • Object reference
  • String reference to a local model
  • String reference to a remote model

There's no need to load/resolve/render unless necessary.

I've also noticed that unnecessary re-rendering happens.

image

But I'm not sure how much it is slowing down.

@lakshmikanthadn
Copy link

We have similar problem, where many of our models have more properties and each property and it sub properties takes lot of time to expand and browser hangs some time to load its properties. It would be helpful if we have a lazy load option for the properties. may be by setting some depth option.
Thanks in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants