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

perf: reduce allocation for parsing #7219

Merged
merged 1 commit into from
Jul 19, 2024
Merged

perf: reduce allocation for parsing #7219

merged 1 commit into from
Jul 19, 2024

Conversation

h-a-n-a
Copy link
Collaborator

@h-a-n-a h-a-n-a commented Jul 18, 2024

Summary

  1. Prefer passing a copy than a pointer
struct DependencyId(u32); // <- 4 bytes

fn foo(d: &DependencyId); // <- usize
⬇️
fn foo(d: DependencyId); // <- 4 bytes

Pointers in rust are usize. On a 32 bit target, this is 4 bytes and on a 64 bit target, this is 8 bytes.
A tuple of a u32 is 4 bytes.

  1. Shadowed Display of Identifier with to_string

Like how other structs are shadowed in the standard library for performance, we shadowed Identifier to gain performance of calling to_string instead of directly calling display.
Calling display basically means calling format!("{}", xxx). This creates additional allocation for formatters.

See also: rust-lang/rust#32586.

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@github-actions github-actions bot added team The issue/pr is created by the member of Rspack. release: performance release: performance related release(mr only) labels Jul 18, 2024
Copy link

netlify bot commented Jul 18, 2024

Deploy Preview for rspack canceled.

Name Link
🔨 Latest commit 4edcc3e
🔍 Latest deploy log https://app.netlify.com/sites/rspack/deploys/669905578f46ed0008a66bef

@h-a-n-a h-a-n-a marked this pull request as ready for review July 18, 2024 12:26
@h-a-n-a h-a-n-a enabled auto-merge (squash) July 18, 2024 12:27
@h-a-n-a h-a-n-a requested a review from JSerFeng July 19, 2024 03:00
@h-a-n-a h-a-n-a merged commit 88c6d6a into main Jul 19, 2024
37 checks passed
@h-a-n-a h-a-n-a deleted the perf-parse branch July 19, 2024 04:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release: performance release: performance related release(mr only) team The issue/pr is created by the member of Rspack.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants