inspect-js / inspect-js/is-string

Slow on the try/catch case

Open
#24 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
22
Forks
5
PR merge metrics
No merged PRs in 30d

Description

While profiling an application, I found `is-string` (and a few related libraries) pretty much topping the charts across the entire codebase:

![image](https://github.com/user-attachments/assets/8a6c525a-8afc-4c9d-b0a4-bf892ada0bbd)

It appears that the try/catch check in `tryStringObject` does not get optimized (due to being a try/catch, I assume) and this makes the type checks very slow, comparatively speaking. It's on a hot path for me due to being used in argument validation code.

The same problem manifests in `is-number-object` and `is-date-object` (and presumably others that happen to not be used in this particular project).

Perhaps this check could be replaced with a faster one in some way, or if not, only applied if the value hits a (faster) test that suggests this check should be applied?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.