Skip to content

Commit 999035c

Browse files
authored
perf(turbopack): Make File => json faster (vercel#81279)
### What? Considering the way `serde_json` works, I expect this to be faster. Also, a JSON string is very likely to be a single `bytes::Bytes` already, so it would not regress the memory usage. ### Why? <img width="843" alt="image" src="https://github.com/user-attachments/assets/2c5ebb0b-335c-4ca1-aebd-64a6da9e0671" />
1 parent c12c9c1 commit 999035c

File tree

1 file changed

+2
-1
lines changed
  • turbopack/crates/turbo-tasks-fs/src

1 file changed

+2
-1
lines changed

turbopack/crates/turbo-tasks-fs/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1912,7 +1912,8 @@ impl FileContent {
19121912
pub fn parse_json_ref(&self) -> FileJsonContent {
19131913
match self {
19141914
FileContent::Content(file) => {
1915-
let de = &mut serde_json::Deserializer::from_reader(file.read());
1915+
let content = file.content.clone().into_bytes();
1916+
let de = &mut serde_json::Deserializer::from_slice(&content);
19161917
match serde_path_to_error::deserialize(de) {
19171918
Ok(data) => FileJsonContent::Content(data),
19181919
Err(e) => FileJsonContent::Unparsable(Box::new(

0 commit comments

Comments
 (0)