Skip to content

Conversation

@h-a-n-a
Copy link
Contributor

@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
@netlify
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
@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.

3 participants