perf: replace flatted with devalue for serialization#9549
Draft
hi-ogawa wants to merge 31 commits intovitest-dev:mainfrom
Draft
perf: replace flatted with devalue for serialization#9549hi-ogawa wants to merge 31 commits intovitest-dev:mainfrom
flatted with devalue for serialization#9549hi-ogawa wants to merge 31 commits intovitest-dev:mainfrom
Conversation
- Add new serialization module to @vitest/utils with parse, stringify, stringifyRaw, stringifyReplace, and toJSON exports - Migrate all flatted imports to use @vitest/utils/serialization - Remove duplicate stringifyReplace implementations - Consistent Error serialization across all usages Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
✅ Deploy Preview for vitest-dev ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
Add examples/demo-8710/ for benchmarking blob reporter output size and merge-reports execution time with configurable test counts. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@vitest/utils/serializationflatted with devalue for serialization
Contributor
Author
|
I will test roudtrip (parse + stringify) as benchmark. |
Contributor
|
I think my PR should be closed #8710 Thanks for looking into it! |
7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
I compared three serialization library.
Here is a benchmark of large blob report serialization (~500 test files, 50000 tests). See https://github.com/hi-ogawa/reproductions/tree/main/vitest-9549-serializer for details.
(Note that
@ungap/structured-clone's data isn't generated through Vitest, but it simply tests equivalent data by converting from flatted result.)and blob file size comparison:
It appears that
flatted's simple implementation has some edge and it's not like modern-ish alternative wins absolutely. For Vitest use case, there's probably no crystal clear reason to replaceflattedat the moment, other than perhaps building our own serializer to pick up the good parts of all. If I would choose one based on my test, I think I'd choosedevalueas it's most battle tested and most flexible, but not sure what others think.Here are some thoughts on options (and non options)
devalue
parseundefinedkey value is included. otherwise smaller thanflatted. it's should be possible to omit these from custom replacer, but haven't tried.stringify@ungap/structured-clone
flattedstructureClone(though Vitest doesn't use them)flattedreplacer/reviverlikeflatted(Vitest needs minor customization onErrorinstance)other options (e.g. seroval, turbo-stream)
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
pnpm-lock.yamlunless you introduce a new test example.Tests
pnpm test:ci.Documentation
pnpm run docscommand.Changesets
feat:,fix:,perf:,docs:, orchore:.