-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
syntax: Join consecutive string literals in format strings together #15832
Conversation
Emit a single rt::Piece per consecutive string literals. String literals are split on {{ or }} escapes. Saves a small amount of static storage and emitted code size.
starting very simple, re: Show bloat #15548 an rt::Piece is 72 bytes, so this saves 144 bytes on the stack in every derived Show impl for structs, mostly zeros, by making sure "Structname { member: " and " }" are just two String pieces instead of four. Does this change pay for itself in "performance" increase vs complexity added? cc @alexcrichton |
Do you have any measurements for the improvements gained here? I don't think that this would save space on the stack because all directives are stored in to rodata, no ton the stack. I would, however, expect this to decrease the size of executables/libraries by at least a bit. This implementation looks good to me, but I'd like to see a measurement of a before/after just to see what we're gaining. |
binary size -- I think the change is very very small
|
Looks like it's still a win to me though! |
Based on an observation that strings and arguments are always interleaved, thanks to #15832. Additionally optimize invocations where formatting parameters are unspecified for all arguments, e.g. `"{} {:?} {:x}"`, by emptying the `__STATIC_FMTARGS` array. Next, `Arguments::new` replaces an empty slice with `None` so that passing empty `__STATIC_FMTARGS` generates slightly less machine code when `Arguments::new` is inlined. Furthermore, formatting itself treats these cases separately without making redundant copies of formatting parameters. All in all, this adds a single mov instruction per `write!` in most cases. That's why code size has increased.
…cola feat: add generate_mut_trait_impl assist ![generate_mut_trait_impl](https://github.com/rust-lang/rust-analyzer/assets/71162630/362a5a93-e109-4ffc-996e-9b6e4f54fcfa) Generate proper `index_mut` method body refer to `index` method body may impossible due to the unpredicable case (rust-lang#15581). Here just leave the `index_mut` method body be same as `index` method body, user can modify it manually to meet their need.
Emit a single rt::Piece for consecutive string literals. String literal chunks
are split on {{ or }} escapes in parsing, and here we join them when expanding.
Saves a small amount of static storage and emitted code size.