Skip to content

Improve speed of serializer test function#516

Merged
layershifter merged 3 commits intomicrosoft:mainfrom
rocketBANG:feature/faster-test
Mar 19, 2024
Merged

Improve speed of serializer test function#516
layershifter merged 3 commits intomicrosoft:mainfrom
rocketBANG:feature/faster-test

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
@github-actions
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
@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.

2 participants