Further optimize code size #278

Merged
Amanieu merged 2 commits from optimize into master 2018-06-08 22:04:34 -05:00
Amanieu commented 2018-06-08 20:52:59 -05:00 (Migrated from github.com)

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.

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 commented 2018-06-08 22:04:31 -05:00 (Migrated from github.com)

Thanks!

Thanks!
alexcrichton commented 2018-06-29 14:50:15 -05:00 (Migrated from github.com)

@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 mind doing a release with this in it? It may actually be a bit of a perf boost as well for the comparisons!
sfackler commented 2018-06-29 15:00:41 -05:00 (Migrated from github.com)

Done!

Done!
Sign in to join this conversation.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-rust-lang/log!278
No description provided.