Skip to content

Commit 355d420

Browse files
Copilothckhanh
andcommitted
Add comprehensive changeset documentation for performance optimizations (#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]>
1 parent 2113f91 commit 355d420

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

.changeset/petite-pumas-flash.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,15 @@
22
"fast-url": patch
33
---
44

5-
[Copilot, update this]
5+
Performance optimizations for path and parameter handling utilities in `src/index.ts`. This release focuses on reducing regex recompilation overhead, optimizing string manipulation for path joining, and improving parameter filtering performance.
6+
7+
**Performance Optimizations:**
8+
9+
- **Pre-compiled regex**: Extracted the path parameter regex (`PATH_PARAM_REGEX`) to module scope to avoid recompiling it on every `path()` call, improving efficiency for path template processing.
10+
- **Optimized `join()` function**: Rewrote to use direct string indexing (`part1[len1 - 1]`, `part2[0]`) instead of `endsWith`/`startsWith` methods, added fast paths for empty strings, and optimized for the most common URL joining scenario where both parts have separators. This reduces unnecessary string slicing and improves speed.
11+
- **Optimized `removeNullOrUndef()` function**: Improved performance by checking for null/undefined values before allocating a new object, and using direct property iteration instead of `Object.entries`/`Object.fromEntries`. This results in faster execution and less memory usage, especially when no filtering is needed.
12+
13+
**Parameter Validation Improvements:**
14+
15+
- Enhanced `validatePathParam()` to check for empty strings in path parameters, ensuring that string path parameters cannot be empty or whitespace-only values.
16+
- Improved code readability by adding blank lines between logical blocks in validation logic.

0 commit comments

Comments
 (0)