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

Improve speed of serializer test function #516

Merged
merged 3 commits into from
Mar 19, 2024

Conversation

rocketBANG
Copy link
Contributor

The test function for the serializer plugin is called many times (from jest docs)

Pay attention to efficiency in test because pretty-format calls it often.
https://github.com/jestjs/jest/tree/main/packages/pretty-format#test

Using the serializer for many elements causes a large slowdown due to the fact it constructs a large regex every time it's called
image (9)

I believe this can be improved because

  1. Both DEBUG_RESET_CLASSES and DEFINITION_LOOKUP_TABLE are maps so we should be able to lookup a class without doing a string search
  2. classes will always be space separated in the string, so we can split the string by spaces to isolate individual classes

This PR changes the test function to use a faster implementation
Simple benchmark test - https://jsperf.app/nevedi
image (6)

@rocketBANG rocketBANG requested a review from a team as a code owner March 11, 2024 22:14
Copy link

github-actions bot commented Mar 11, 2024

📊 Bundle size report

🤖 This report was generated against 3e815c80ed89c72c8a81b5d8082cac7e8bb7a285

Copy link
Member

@layershifter layershifter left a comment

Choose a reason for hiding this comment

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

Love it, thx ❤️

@layershifter layershifter merged commit beaffe6 into microsoft:main Mar 19, 2024
4 checks passed
@rocketBANG rocketBANG deleted the feature/faster-test branch March 19, 2024 16:45
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.

None yet

2 participants