dtolnay / quote

Rust quasi-quoting
Apache License 2.0
1.32k stars 90 forks source link

Order rules in `quote_token!` and `quote_token_spanned!` by frequency. #209

Closed nnethercote closed 2 years ago

nnethercote commented 2 years ago

This reduces cargo check times by 4-9% on a few crates that use quote! heavily.

nnethercote commented 2 years ago

Here are some cargo-check measurements done with the harness from rustc-perf and six crates known to use quote! heavily.

Benchmark & Profile Scenario % Change Significance Factor?
pest_generator-2.1.3 check incr-unchanged -9.59% 47.97x
num-derive-0.3.3 check incr-unchanged -9.31% 46.55x
futures-macro-0.3.19 check incr-unchanged -7.71% 38.56x
mockall_derive-0.11.0 check incr-unchanged -7.69% 38.45x
pest_generator-2.1.3 check full -5.88% 29.42x
num-derive-0.3.3 check full -5.63% 28.14x
pest_generator-2.1.3 check incr-full -5.34% 26.68x
num-derive-0.3.3 check incr-full -5.24% 26.20x
futures-macro-0.3.19 check full -4.64% 23.18x
mockall_derive-0.11.0 check full -4.31% 21.54x
futures-macro-0.3.19 check incr-full -4.05% 20.24x
mockall_derive-0.11.0 check incr-full -3.90% 19.48x
scroll_derive-0.11.0 check incr-full -0.00% 0.01x
scroll_derive-0.11.0 check full 0.00% 0.01x
ctor-0.1.21 check full -0.00% 0.00x
ctor-0.1.21 check incr-unchanged -0.00% 0.00x
ctor-0.1.21 check incr-full -0.00% 0.00x
scroll_derive-0.11.0 check incr-unchanged -0.00% 0.00x
nnethercote commented 2 years ago

Would swapping the two token arguments of quote_token! help?

Quite possibly. I'll try it tomorrow, and likewise for the macros above quote_token!.

lqd commented 2 years ago

I was curious and tried David's suggestion: it does indeed improve things a tiny bit.

Benchmark & Profile | Scenario | % Change | Significance Factor ? -- | -- | -- | -- pest_generator-2.1.3 check | incr-unchanged | -2.18% | 10.91x num-derive-0.3.3 check | incr-unchanged | -2.05% | 10.26x mockall_derive-0.11.0 check | incr-unchanged | -1.79% | 8.97x pest_generator-2.1.3 check | full | -1.34% | 6.69x num-derive-0.3.3 check | full | -1.21% | 6.06x pest_generator-2.1.3 check | incr-full | -1.18% | 5.90x futures-macro-0.3.19 check | incr-unchanged | -1.17% | 5.86x num-derive-0.3.3 check | incr-full | -1.09% | 5.47x mockall_derive-0.11.0 check | full | -1.00% | 5.00x mockall_derive-0.11.0 check | incr-full | -0.88% | 4.39x futures-macro-0.3.19 check | full | -0.71% | 3.57x futures-macro-0.3.19 check | incr-full | -0.61% | 3.06x

I'll open a PR shortly.