Skip to content

Further optimize code size#278

Merged
sfackler merged 2 commits into
rust-lang:masterfrom
Amanieu:optimize
Jun 9, 2018
Merged

Further optimize code size#278
sfackler merged 2 commits into
rust-lang:masterfrom
Amanieu:optimize

Conversation

@Amanieu
Copy link
Copy Markdown
Member

@Amanieu Amanieu commented Jun 9, 2018

I had a look at #276 and thought I could do better!

There basically two areas where an improvement can be found:

  • LLVM generates pretty poor code for the default implementations of PartialOrd::{lt,le,gt,ge} which forward to partial_cmp. So I added versions which perform the desired comparison directly.
  • The target and location are almost always compile-time constants and can be passed in as a single argument which points to a static constant. This unfortunately doesn't work for the log level since we first need to make a local copy of it so that it is only evaluated once.

A main function containing nothing but warn!("hello world") shrinks from 160 bytes to 98 bytes in x86_64 with this change.

@sfackler
Copy link
Copy Markdown
Member

sfackler commented Jun 9, 2018

Thanks!

@sfackler sfackler merged commit 1b24f84 into rust-lang:master Jun 9, 2018
@alexcrichton
Copy link
Copy Markdown
Member

@sfackler mind doing a release with this in it? It may actually be a bit of a perf boost as well for the comparisons!

@sfackler
Copy link
Copy Markdown
Member

Done!

EFanZh pushed a commit to EFanZh/log that referenced this pull request Jul 23, 2023
Optimize `target::linux::detect_target_linux`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants