diff --git a/bson/bson.h b/bson/bson.h index 0ad7a2ca55c..9515adfd829 100644 --- a/bson/bson.h +++ b/bson/bson.h @@ -105,7 +105,6 @@ namespace mongo { #include "oid.h" #include "bsonelement.h" #include "bsonobj.h" - #include "bsonobjbuilder.h" #include "bsonobjiterator.h" #include "bson-inl.h" diff --git a/bson/inline_decls.h b/bson/inline_decls.h index afe926c60e7..cc28aee7b98 100644 --- a/bson/inline_decls.h +++ b/bson/inline_decls.h @@ -30,3 +30,29 @@ #define NOINLINE_DECL #endif + + +/* Note: do not clutter code with these -- ONLY use in hot spots / significant loops. */ + +//#if 1 + +//#if !defined(__GNUC__) + +// branch prediction. indicate we expect to enter the if statement body +#define MONGOIF(x) if( (x) ) + +// branch prediction. indicate we expect to not enter the if statement body +#define MONGO_IF(x) if( (x) ) + +// prefetch data from memory +#define MONGOPREFETCH(x) { /*just check we compile:*/ sizeof(*x); } + +#if 0 + +#define IF(x) if( __builtin_expect((x), 1) ) + +#define _IF(x) if( __builtin_expect((x), 0) ) + +#define PREFETCH(x) { /*just check we compile:*/ sizeof(*x); } + +#endif diff --git a/db/dur_preplogbuffer.cpp b/db/dur_preplogbuffer.cpp index d1f05a5cede..5851e415408 100644 --- a/db/dur_preplogbuffer.cpp +++ b/db/dur_preplogbuffer.cpp @@ -35,6 +35,7 @@ #include "../util/alignedbuilder.h" #include "../util/timer.h" #include "dur_stats.h" +#include "../server.h" using namespace mongoutils; @@ -59,7 +60,7 @@ namespace mongo { size_t ofs = 1; MongoMMF *mmf = findMMF_inlock(i->start(), /*out*/ofs); - if( !mmf->willNeedRemap() ) { + _IF( !mmf->willNeedRemap() ) { // tag this mmf as needed a remap of its private view later. // usually it will already be dirty/already set, so we do the if above first // to avoid possibility of cpu cache line contention @@ -96,7 +97,7 @@ namespace mongo { #endif bb.appendBuf(i->start(), e.len); - if (e.len != (unsigned)i->length()) { + _IF (e.len != (unsigned)i->length()) { log() << "journal info splitting prepBasicWrite at boundary" << endl; // This only happens if we write to the last byte in a file and @@ -119,9 +120,21 @@ namespace mongo { // each time events switch to a different database we journal a JDbContext RelativePath lastDbPath; - for( set::iterator i = commitJob.writes().begin(); i != commitJob.writes().end(); i++ ) { - prepBasicWrite_inlock(bb, &(*i), lastDbPath); - } + set::iterator i = commitJob.writes().begin(); + + const WriteIntent *w = &(*i); + while(1) { + i++; + const WriteIntent *next = 0; + IF( i != commitJob.writes().end() ) { + next = &(*i); + PREFETCH(next); + } + prepBasicWrite_inlock(bb, w, lastDbPath); + _IF( next == 0 ) + break; + w = next; + }; } void resetLogBuffer(AlignedBuilder& bb) { diff --git a/dbtests/test.vcxproj b/dbtests/test.vcxproj index 976682e11ff..319ae8d9a64 100644 --- a/dbtests/test.vcxproj +++ b/dbtests/test.vcxproj @@ -1,4 +1,4 @@ - + @@ -219,6 +219,7 @@ + diff --git a/dbtests/test.vcxproj.filters b/dbtests/test.vcxproj.filters index 572941e99d2..530c4267db0 100755 --- a/dbtests/test.vcxproj.filters +++ b/dbtests/test.vcxproj.filters @@ -301,6 +301,9 @@ db\cpp + + db\h + @@ -515,33 +518,18 @@ util\cpp - - util\cpp - util\cpp util\cpp - - util\cpp - - - util\cpp - - - util\cpp - util\cpp util\cpp - - util\cpp - util\cpp @@ -845,6 +833,27 @@ db\cpp + + db\cpp + + + db\cpp + + + db\cpp + + + db\cpp + + + db\cpp + + + db\cpp + + + db\cpp + diff --git a/server.h b/server.h new file mode 100644 index 00000000000..066b87db989 --- /dev/null +++ b/server.h @@ -0,0 +1,23 @@ +/** @file server.h + + This file contains includes commonly needed in the server files (mongod, mongos, test). It is NOT included in the C++ client. + + Over time we should move more here, and more out of pch.h. And get rid of pch.h at some point. +*/ + +// todo is there a boost thign for this already? + +#pragma once + +#include "bson/inline_decls.h" + +/* Note: do not clutter code with these -- ONLY use in hot spots / significant loops. */ + +// branch prediction. indicate we expect to enter the if statement body +#define IF MONGOIF + +// branch prediction. indicate we expect to not enter the if statement body +#define _IF MONGO_IF + +// prefetch data from memory +#define PREFETCH MONGOPREFETCH