Skip to content

Conversation

@hckhanh
Copy link
Owner

@hckhanh hckhanh commented Nov 12, 2025

This release focuses on performance optimizations for path and parameter handling utilities in src/index.ts. The main improvements include reducing regex recompilation overhead, optimizing string manipulation for path joining, and making parameter filtering faster by avoiding unnecessary object allocations.

Performance optimizations:

  • Pre-compiled the path parameter regex (PATH_PARAM_REGEX) to avoid recompiling it on every call, improving efficiency in the path function.
  • Rewrote the join function to use direct string indexing instead of endsWith/startsWith, and added fast paths for empty strings and common URL joining cases, reducing unnecessary string slicing and improving speed.

Parameter handling improvements:

  • Optimized removeNullOrUndef by checking for null/undefined values before allocating a new object, and using direct property iteration instead of Object.entries/Object.fromEntries, resulting in faster execution and less memory usage.

Copilot AI review requested due to automatic review settings November 12, 2025 05:00
@hckhanh hckhanh self-assigned this Nov 12, 2025
@codecov
Copy link

codecov bot commented Nov 12, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (5a1fe77) to head (355d420).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #82   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            3         3           
  Lines          191       216   +25     
  Branches        63        73   +10     
=========================================
+ Hits           191       216   +25     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot finished reviewing on behalf of hckhanh November 12, 2025 05:01
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR optimizes the path function by adding a fast-path early return for templates that don't contain parameter placeholders (:param patterns), avoiding unnecessary object cloning and regex operations.

Key changes:

  • Added an early return check using indexOf(':') to detect templates without parameters
  • Added blank lines to improve code readability

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codspeed-hq
Copy link

codspeed-hq bot commented Nov 12, 2025

CodSpeed Performance Report

Merging #82 will improve performances by 44.55%

Comparing optimize (355d420) with main (5a1fe77)

Summary

⚡ 19 improvements
✅ 139 untouched
⏩ 22 skipped1

Benchmarks breakdown

Benchmark BASE HEAD Change
Join with separator at end of first part 17 µs 15.4 µs +10.62%
Join URL with trailing slash 16.8 µs 14.4 µs +16.23%
Complex URL with many params (original test) 182.2 µs 141.3 µs +28.97%
Deep path with 5 parameters 118.4 µs 100.8 µs +17.49%
Large query string (15 params) 151.5 µs 104.8 µs +44.55%
Large query string (15 params) with some path params 166.6 µs 120.3 µs +38.47%
Array in query params 84.7 µs 67.5 µs +25.46%
Base template only (no path) 98.2 µs 80.5 µs +22.09%
Boolean and number params 113.8 µs 94.4 µs +20.5%
Multiple query params (5 params) 111.2 µs 86.4 µs +28.69%
Path params with special characters 113.1 µs 96.4 µs +17.34%
Two path params + two query params 112.6 µs 100.6 µs +11.92%
REST API endpoint with pagination 85.7 µs 74.8 µs +14.64%
Resource with ID and nested resource 101.8 µs 84.8 µs +20.05%
Search endpoint with filters 96.1 µs 72.6 µs +32.37%
URL with port number 99.8 µs 82.3 µs +21.18%
Base URL with trailing slash + path 31 µs 25.4 µs +21.89%
Concatenate base URL and path only 76.6 µs 67.1 µs +14.02%
Single query parameter 92.9 µs 72.5 µs +28.13%

Footnotes

  1. 22 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@hckhanh hckhanh force-pushed the optimize branch 2 times, most recently from 8f6ceca to 03d2b97 Compare November 12, 2025 05:42
@hckhanh hckhanh changed the title Optimize path function to handle templates without parameters more efficiently. Optimize join function for common boundary scenarios and remove unused fast path logic in path Nov 12, 2025
@hckhanh hckhanh force-pushed the optimize branch 3 times, most recently from 5e970b8 to 3ef774c Compare November 12, 2025 06:59
@hckhanh hckhanh changed the title Optimize join function for common boundary scenarios and remove unused fast path logic in path Optimize path, join, and removeNullOrUndef functions for performance and clarity, introduce regex pre-compilation, and improve path parameter validation. Nov 12, 2025
@hckhanh
Copy link
Owner Author

hckhanh commented Nov 12, 2025

@copilot analyze this PR and add changesets to .changeset/petite-pumas-flash.md

Copy link

Copilot AI commented Nov 12, 2025

@hckhanh I've opened a new pull request, #84, to work on those changes. Once the pull request is ready, I'll request review from you.

@hckhanh
Copy link
Owner Author

hckhanh commented Nov 12, 2025

@copilot add to copilot instruction:

How to add changesets

  1. Run changeset add to generate changeset file
  2. Fill out release changes for the changesets.

Copy link

Copilot AI commented Nov 12, 2025

@hckhanh I've opened a new pull request, #85, to work on those changes. Once the pull request is ready, I'll request review from you.

hckhanh and others added 8 commits November 12, 2025 14:29
…essary object allocation and using direct property iteration.
…ns (#84)

* Initial plan

* Update changeset with comprehensive PR analysis and detailed optimization descriptions

Co-authored-by: hckhanh <[email protected]>

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: hckhanh <[email protected]>
@sonarqubecloud
Copy link

@hckhanh hckhanh merged commit 5b7ec21 into main Nov 12, 2025
14 checks passed
@hckhanh hckhanh deleted the optimize branch November 12, 2025 07:34
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