scalar / openapi-parser

Modern OpenAPI parser written in TypeScript
MIT License
34 stars 1 forks source link

chore: add benchmarks #73

Closed hanspagel closed 4 months ago

hanspagel commented 4 months ago

This PR adds some benchmarks to compare the performance of @apidevtools/swagger-parser and @scalar/openapi-parser.

This also helped me to find a performance bottleneck: We used to asynchronously import the OpenAPI schemas, which really slowed down the first use. With this PR they are imported and bundled right-away.

There are some other things we could improve:

Anyway. I’m not sure whether we compare apples to apples (SwaggerParser.dereference vs. our resolveReferences). I think SwaggerParser does validation and dereferencing in one go and we’re way slower then (1.000×). But with the above mentioned refactors we should come close.

Run benchmarks

pnpm run bench

Create CPU profile

pnpm run profile

Anyway, those are the results for now (no reference, single reference, petstore):

Screenshot 2024-04-23 at 13 30 41
relativeci[bot] commented 4 months ago

Job #5: Bundle Size — 478.13KiB (-0.21%).

715bbff(current) vs 42ab310 main#4(baseline)

Bundle metrics  Change 5 changes Regression 1 regression
                 Current
Job #5
     Baseline
Job #4
Regression  Initial JS 478.13KiB(+23.89%) 385.93KiB
No change  Initial CSS 0B 0B
Change  Cache Invalidation 100% 0%
Change  Chunks 1(-75%) 4
Change  Assets 1(-75%) 4
Change  Modules 302(-0.33%) 303
No change  Duplicate Modules 0 0
No change  Duplicate Code 0% 0%
No change  Packages 10 10
No change  Duplicate Packages 0 0

Bundle size by type  Change 1 change Improvement 1 improvement
|            |       Current
[Job #5](https://app.relative-ci.com/projects/hXQ54UQKluDUZAKvpt9b/jobs/5-ADoFpzVn6jwO2IHRRKzr?utm_source=github&utm_medium=pr-report "View job report") |      Baseline
[Job #4](https://app.relative-ci.com/projects/hXQ54UQKluDUZAKvpt9b/jobs/4-WxI2NBTBrDxg1rZF3Bzs?utm_source=github&utm_medium=pr-report "View baseline job report") | |:--|--:|--:| | Improvement  [JS](https://app.relative-ci.com/projects/hXQ54UQKluDUZAKvpt9b/jobs/5-ADoFpzVn6jwO2IHRRKzr/assets?ba=%7B%22filters%22%3A%22ft.CSS-0_ft.JS-1_ft.IMG-0_ft.MEDIA-0_ft.FONT-0_ft.HTML-0_ft.OTHER-0%22%7D "View JS assets") | `478.13KiB` (`-0.21%`) | `479.15KiB` |

View job #5 reportView chore/benchmarking branch activityView project dashboard