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

Use Map for rule search and add benchmark #334

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Conversation

lupomontero
Copy link
Owner

@lupomontero lupomontero commented Nov 25, 2024

This PR includes the changes proposed by @gugu's in #302 as well as on other minor tweaks (like only iterating over the rules once instead of twice on module load).

This increases performance (ops/sec) by a factor of over 100!!

The main change is using a Map object and indexing it by punySuffix. This allows searching by punySuffix without having to iterate over the thousands of rules.

npm run benchmark

> [email protected] benchmark
> node --experimental-vm-modules --no-warnings benchmark/suite.js

┌────────────────────────────────────┬─────────┬──────┬──────────────┐
│ (index)                            │ ops/sec │ ± %  │ runs sampled │
├────────────────────────────────────┼─────────┼──────┼──────────────┤
│ [source] psl#isValid               │ 367385  │ 3.76 │ 85           │
│ [source] psl#parse                 │ 396952  │ 1.22 │ 93           │
│ [source] psl#parse invalid domain  │ 429242  │ 1.25 │ 92           │
│ [v1.13.0] psl#isValid              │ 3306    │ 1.62 │ 87           │
│ [v1.13.0] psl#parse                │ 3402    │ 2.07 │ 89           │
│ [v1.13.0] psl#parse invalid domain │ 3230    │ 1.53 │ 87           │
└────────────────────────────────────┴─────────┴──────┴──────────────┘
┌──────────────────────────┬────────┬─────────┬──────────────┐
│ (index)                  │ source │ v1.13.0 │ diff         │
├──────────────────────────┼────────┼─────────┼──────────────┤
│ psl#isValid              │ 367385 │ 3306    │ '111.13x up' │
│ psl#parse                │ 396952 │ 3402    │ '116.68x up' │
│ psl#parse invalid domain │ 429242 │ 3230    │ '132.89x up' │
└──────────────────────────┴────────┴─────────┴──────────────┘

gugu and others added 6 commits November 25, 2024 15:54
The benchmark script now runs the suite both for the local version of
the source code and v1.13.0, which is fetched from a CDN.
This avoids having to iterate over all the rules to parse them first and
then again to build the map.

It also simplifies implementation by not expecting more than one rule
for a given punySuffix.
@lupomontero lupomontero self-assigned this Nov 25, 2024
@lupomontero lupomontero linked an issue Nov 25, 2024 that may be closed by this pull request
@lupomontero lupomontero marked this pull request as ready for review November 25, 2024 16:03
@lupomontero lupomontero mentioned this pull request Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Performance issues - iterating over 9k rules for every domain
2 participants