Skip to content

Commit

Permalink
Define cfg(rtopt) when optimizing. Turn off runtime sanity checks
Browse files Browse the repository at this point in the history
Naturally, and sadly, turning off sanity checks in the runtime is
a noticable performance win. The particular test I'm running goes from
~1.5 s to ~1.3s.

Sanity checks are turned *on* when not optimizing, or when cfg
includes `rtdebug` or `rtassert`.
  • Loading branch information
brson committed Aug 24, 2013
1 parent 4c75d36 commit 30a7a5b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ ifdef CFG_DISABLE_OPTIMIZE
$(info cfg: disabling rustc optimization (CFG_DISABLE_OPTIMIZE))
CFG_RUSTC_FLAGS +=
else
CFG_RUSTC_FLAGS += -O
# The rtopt cfg turns off runtime sanity checks
CFG_RUSTC_FLAGS += -O --cfg rtopt
endif

ifdef CFG_ENABLE_DEBUG
Expand Down
6 changes: 4 additions & 2 deletions src/libstd/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ macro_rules! rtdebug (

macro_rules! rtassert (
( $arg:expr ) => ( {
if !$arg {
rtabort!("assertion failed: %s", stringify!($arg));
if ::rt::util::ENFORCE_SANITY {
if !$arg {
rtabort!("assertion failed: %s", stringify!($arg));
}
}
} )
)
Expand Down
3 changes: 3 additions & 0 deletions src/libstd/rt/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ use unstable::atomics::{AtomicInt, INIT_ATOMIC_INT, SeqCst};
#[cfg(target_os="macos")]
use unstable::running_on_valgrind;

// Indicates whether we should perform expensive sanity checks, including rtassert!
pub static ENFORCE_SANITY: bool = !cfg!(rtopt) || cfg!(rtdebug) || cfg!(rtassert);

/// Get the number of cores available
pub fn num_cpus() -> uint {
#[fixed_stack_segment]; #[inline(never)];
Expand Down

0 comments on commit 30a7a5b

Please sign in to comment.