Skip to content

⚡ Optimize string concatenation in Swagger generator#8

Merged
sebamar88 merged 1 commit intomainfrom
performance-swagger-generator-optimization-12535992926310954052
Mar 17, 2026
Merged

⚡ Optimize string concatenation in Swagger generator#8
sebamar88 merged 1 commit intomainfrom
performance-swagger-generator-optimization-12535992926310954052

Conversation

@sebamar88
Copy link
Copy Markdown
Owner

💡 What:

Optimized the string generation logic in src/cli/swagger-generator.ts by replacing string concatenation (+=) with an array of strings that are joined at the end using .join('\n\n').

🎯 Why:

Iterative string concatenation in JavaScript/TypeScript can lead to performance issues, especially when generating large files, due to the creation of many intermediate string objects. Using an array and a single join operation is more efficient and idiomatic.

📊 Measured Improvement:

I established a baseline using a benchmark script with 50,000 mock schemas:

  • Average Concatenation Time: 189.65ms
  • Average Array Join Time: 170.13ms
  • Measured Improvement: 10.29%

The optimization provides a measurable boost in performance for large OpenAPI specifications while maintaining exactly the same output format.


PR created automatically by Jules for task 12535992926310954052 started by @sebamar88

Replaced iterative string concatenation with an array-based approach
using `join('\n\n')` for better performance and cleaner code when
generating large TypeScript files.

Benchmark results (50,000 schemas):
- Baseline (concatenation): 189.65ms
- Optimized (array join): 170.13ms
- Improvement: ~10.3%

Co-authored-by: sebamar88 <4359231+sebamar88@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@github-actions
Copy link
Copy Markdown
Contributor

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@github-actions
Copy link
Copy Markdown
Contributor

📦 Bundle Size Report

Total dist size: 1.1M

View detailed breakdown
4.0K	dist/api-client.d.ts
4.0K	dist/api-client.d.ts.map
4.0K	dist/api-client.js
4.0K	dist/api-client.js.map
76K	dist/cli
4.0K	dist/debug.d.ts
4.0K	dist/debug.d.ts.map
4.0K	dist/debug.js
4.0K	dist/debug.js.map
4.0K	dist/env-manager.d.ts
4.0K	dist/env-manager.d.ts.map
4.0K	dist/env-manager.js
4.0K	dist/env-manager.js.map
4.0K	dist/file-upload.d.ts
4.0K	dist/file-upload.d.ts.map
4.0K	dist/file-upload.js
4.0K	dist/file-upload.js.map
4.0K	dist/index.d.ts
4.0K	dist/index.d.ts.map
4.0K	dist/index.js
4.0K	dist/index.js.map
4.0K	dist/logger.d.ts
4.0K	dist/logger.d.ts.map
4.0K	dist/logger.js
4.0K	dist/logger.js.map
4.0K	dist/profiler.d.ts
4.0K	dist/profiler.d.ts.map
4.0K	dist/profiler.js
4.0K	dist/profiler.js.map
4.0K	dist/response-validator.d.ts
4.0K	dist/response-validator.d.ts.map
4.0K	dist/response-validator.js
4.0K	dist/response-validator.js.map
4.0K	dist/retry-policy.d.ts
4.0K	dist/retry-policy.d.ts.map
4.0K	dist/retry-policy.js
4.0K	dist/retry-policy.js.map
4.0K	dist/storage-utils.d.ts
4.0K	dist/storage-utils.d.ts.map
4.0K	dist/storage-utils.js
4.0K	dist/storage-utils.js.map
4.0K	dist/streaming.d.ts
4.0K	dist/streaming.d.ts.map
4.0K	dist/streaming.js
4.0K	dist/streaming.js.map
204K	dist/utils/async
304K	dist/utils/helpers
296K	dist/utils/core
824K	dist/utils
4.0K	dist/websocket.d.ts
4.0K	dist/websocket.d.ts.map
4.0K	dist/websocket.js
4.0K	dist/websocket.js.map

@sonarqubecloud
Copy link
Copy Markdown

@github-actions
Copy link
Copy Markdown
Contributor

📊 Code Coverage Report

Coverage: 91.53% ✅

Great coverage!

View full coverage report

@github-actions
Copy link
Copy Markdown
Contributor

📊 Code Coverage Report

Coverage: %

❌ Low coverage - please add more tests

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 17, 2026

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@sebamar88 sebamar88 merged commit efe7682 into main Mar 17, 2026
17 checks passed
sebamar88 added a commit that referenced this pull request Mar 29, 2026
- Run prettier --write across 19 files to fix format:check failures
  (src/cli/index.ts, src/utils/async/{index,pipeline,promise-pool}.ts,
  src/utils/core/ApiClient.ts, src/utils/helpers/{StreamingHelper,UrlHelper}.ts,
  tests/{async/*,bytekit-cli,ddd-boilerplate,pipeline,request-queue-api-client,
  streaming-helper,url-helper,websocket-helper}.test.ts)
- Standardize pnpm version to 9 in ci.yml build job (was 8, coverage/security already 9)
- Fill CHANGELOG.md entries for v2.2.1, v2.2.2, v2.2.3 with real feature content:
  v2.2.3: Pipeline (pipe/map/filter/reduce, bytekit/pipeline export, 20 tests)
  v2.2.2: WebSocket backoff/validation/pong + RequestQueue/RequestBatcher (47 tests)
  v2.2.1: FileUploadHelper resumeFrom/concurrency/uploadedChunks/totalChunks + ApiClient fix

All CI checks pass locally: lint 0 errors, format:check clean, typecheck clean,
708 tests passing.
sebamar88 added a commit that referenced this pull request Mar 29, 2026
- Run prettier --write across 19 files to fix format:check failures
  (src/cli/index.ts, src/utils/async/{index,pipeline,promise-pool}.ts,
  src/utils/core/ApiClient.ts, src/utils/helpers/{StreamingHelper,UrlHelper}.ts,
  tests/{async/*,bytekit-cli,ddd-boilerplate,pipeline,request-queue-api-client,
  streaming-helper,url-helper,websocket-helper}.test.ts)
- Standardize pnpm version to 9 in ci.yml build job (was 8, coverage/security already 9)
- Fill CHANGELOG.md entries for v2.2.1, v2.2.2, v2.2.3 with real feature content:
  v2.2.3: Pipeline (pipe/map/filter/reduce, bytekit/pipeline export, 20 tests)
  v2.2.2: WebSocket backoff/validation/pong + RequestQueue/RequestBatcher (47 tests)
  v2.2.1: FileUploadHelper resumeFrom/concurrency/uploadedChunks/totalChunks + ApiClient fix

All CI checks pass locally: lint 0 errors, format:check clean, typecheck clean,
708 tests passing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants