Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize type selector by using pattern match #536

Merged
merged 1 commit into from
Feb 16, 2024

Conversation

ypconstante
Copy link
Contributor

Today the namespace and type matching use String.split to get the namespace and type of an element.
Using pattern matching instead of String.split provides a significant performance improvement, bringing the type selector performance closer to the id selector.


##### With input big #####
Name                             ips        average  deviation         median         99th %
id                            477.46        2.09 ms    ±20.92%        1.91 ms        3.45 ms
tag name (type) (pr)          384.54        2.60 ms    ±24.84%        2.31 ms        4.64 ms
tag name (type) (main)        158.85        6.30 ms    ±13.58%        6.04 ms        9.55 ms

Comparison: 
id                            477.46
tag name (type) (pr)          384.54 - 1.24x slower +0.51 ms
tag name (type) (main)        158.85 - 3.01x slower +4.20 ms

Memory usage statistics:

Name                      Memory usage
id                             1.87 MB
tag name (type) (pr)           2.38 MB - 1.27x memory usage +0.51 MB
tag name (type) (main)         2.32 MB - 1.24x memory usage +0.44 MB

**All measurements for memory usage were the same**

##### With input medium #####
Name                             ips        average  deviation         median         99th %
id                            1.63 K      614.22 μs    ±18.49%      585.52 μs     1119.25 μs
tag name (type) (pr)          1.42 K      704.90 μs    ±18.72%      665.53 μs     1316.34 μs
tag name (type) (main)        0.49 K     2021.96 μs    ±14.88%     1922.66 μs     3115.66 μs

Comparison: 
id                            1.63 K
tag name (type) (pr)          1.42 K - 1.15x slower +90.68 μs
tag name (type) (main)        0.49 K - 3.29x slower +1407.73 μs

Memory usage statistics:

Name                      Memory usage
id                           621.45 KB
tag name (type) (pr)         828.10 KB - 1.33x memory usage +206.66 KB
tag name (type) (main)       771.63 KB - 1.24x memory usage +150.19 KB

**All measurements for memory usage were the same**

##### With input small #####
Name                             ips        average  deviation         median         99th %
id                            7.70 K      129.89 μs    ±21.73%      118.59 μs      255.17 μs
tag name (type) (pr)          7.13 K      140.24 μs    ±20.30%      128.30 μs      263.55 μs
tag name (type) (main)        2.50 K      400.29 μs    ±18.44%      369.09 μs      712.48 μs

Comparison: 
id                            7.70 K
tag name (type) (pr)          7.13 K - 1.08x slower +10.35 μs
tag name (type) (main)        2.50 K - 3.08x slower +270.40 μs

Memory usage statistics:

Name                      Memory usage
id                           127.27 KB
tag name (type) (pr)         165.11 KB - 1.30x memory usage +37.84 KB
tag name (type) (main)       156.77 KB - 1.23x memory usage +29.50 KB

Copy link
Owner

@philss philss left a comment

Choose a reason for hiding this comment

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

🚀

@philss philss merged commit c6f28eb into philss:main Feb 16, 2024
9 checks passed
@ypconstante ypconstante deleted the optimize-type-matching branch February 17, 2024 13:56
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