diff options
author | Geert Bosch <geert@mongodb.com> | 2018-08-03 19:20:05 -0400 |
---|---|---|
committer | Geert Bosch <geert@mongodb.com> | 2018-08-03 19:20:05 -0400 |
commit | ecb0b6c6dfb854f53c3e4fa05aa61bb9a1bed554 (patch) | |
tree | 6dbc24d26c39bc70f3c1fae5cd35b2b757e5bcd5 /src/mongo/bson | |
parent | 806b9c32dff674b72110f2acd8604e950afab102 (diff) | |
download | mongo-ecb0b6c6dfb854f53c3e4fa05aa61bb9a1bed554.tar.gz |
Revert "SERVER-36108 speed up BSONArrayBuilder by counting in decimal"
This reverts commit ce9968b484b95fe3f08ffe1d15791e8fadc9e854.
Diffstat (limited to 'src/mongo/bson')
-rw-r--r-- | src/mongo/bson/SConscript | 10 | ||||
-rw-r--r-- | src/mongo/bson/bsonobjbuilder.h | 70 | ||||
-rw-r--r-- | src/mongo/bson/bsonobjbuilder_bm.cpp | 52 |
3 files changed, 36 insertions, 96 deletions
diff --git a/src/mongo/bson/SConscript b/src/mongo/bson/SConscript index f1d9ab122ea..fbe9ef1dae0 100644 --- a/src/mongo/bson/SConscript +++ b/src/mongo/bson/SConscript @@ -65,16 +65,6 @@ env.CppUnitTest( ], ) -env.Benchmark( - target='bsonobjbuilder_bm', - source=[ - 'bsonobjbuilder_bm.cpp', - ], - LIBDEPS=[ - '$BUILD_DIR/mongo/base', - ], -) - env.CppUnitTest( target='bsonelement_test', source=[ diff --git a/src/mongo/bson/bsonobjbuilder.h b/src/mongo/bson/bsonobjbuilder.h index ef92065d9a0..6162495c1cd 100644 --- a/src/mongo/bson/bsonobjbuilder.h +++ b/src/mongo/bson/bsonobjbuilder.h @@ -48,7 +48,7 @@ #include "mongo/bson/util/builder.h" #include "mongo/platform/decimal128.h" #include "mongo/stdx/type_traits.h" -#include "mongo/util/decimal_counter.h" +#include "mongo/util/itoa.h" namespace mongo { @@ -810,20 +810,20 @@ private: class BSONArrayBuilder { public: - BSONArrayBuilder() {} - BSONArrayBuilder(BufBuilder& _b) : _b(_b) {} - BSONArrayBuilder(int initialSize) : _b(initialSize) {} + BSONArrayBuilder() : _i(0), _b() {} + BSONArrayBuilder(BufBuilder& _b) : _i(0), _b(_b) {} + BSONArrayBuilder(int initialSize) : _i(0), _b(initialSize) {} template <typename T> BSONArrayBuilder& append(const T& x) { - _b.append(_fieldCount, x); - ++_fieldCount; + ItoA itoa(_i++); + _b.append(itoa, x); return *this; } BSONArrayBuilder& append(const BSONElement& e) { - _b.appendAs(e, _fieldCount); - ++_fieldCount; + ItoA itoa(_i++); + _b.appendAs(e, itoa); return *this; } @@ -833,19 +833,19 @@ public: template <typename T> BSONArrayBuilder& operator<<(const T& x) { - _b << _fieldCount << x; - ++_fieldCount; + ItoA itoa(_i++); + _b << itoa << x; return *this; } void appendNull() { - _b.appendNull(_fieldCount); - ++_fieldCount; + ItoA itoa(_i++); + _b.appendNull(itoa); } void appendUndefined() { - _b.appendUndefined(_fieldCount); - ++_fieldCount; + ItoA itoa(_i++); + _b.appendUndefined(itoa); } /** @@ -875,57 +875,59 @@ public: // These two just use next position BufBuilder& subobjStart() { - return _b.subobjStart(_fieldCount++); + ItoA itoa(_i++); + return _b.subobjStart(itoa); } BufBuilder& subarrayStart() { - return _b.subarrayStart(_fieldCount++); + ItoA itoa(_i++); + return _b.subarrayStart(itoa); } BSONArrayBuilder& appendRegex(StringData regex, StringData options = "") { - _b.appendRegex(_fieldCount, regex, options); - ++_fieldCount; + ItoA itoa(_i++); + _b.appendRegex(itoa, regex, options); return *this; } BSONArrayBuilder& appendBinData(int len, BinDataType type, const void* data) { - _b.appendBinData(_fieldCount, len, type, data); - ++_fieldCount; + ItoA itoa(_i++); + _b.appendBinData(itoa, len, type, data); return *this; } BSONArrayBuilder& appendCode(StringData code) { - _b.appendCode(_fieldCount, code); - ++_fieldCount; + ItoA itoa(_i++); + _b.appendCode(itoa, code); return *this; } BSONArrayBuilder& appendCodeWScope(StringData code, const BSONObj& scope) { - _b.appendCodeWScope(_fieldCount, code, scope); - ++_fieldCount; + ItoA itoa(_i++); + _b.appendCodeWScope(itoa, code, scope); return *this; } BSONArrayBuilder& appendTimeT(time_t dt) { - _b.appendTimeT(_fieldCount, dt); - ++_fieldCount; + ItoA itoa(_i++); + _b.appendTimeT(itoa, dt); return *this; } BSONArrayBuilder& appendDate(Date_t dt) { - _b.appendDate(_fieldCount, dt); - ++_fieldCount; + ItoA itoa(_i++); + _b.appendDate(itoa, dt); return *this; } BSONArrayBuilder& appendBool(bool val) { - _b.appendBool(_fieldCount, val); - ++_fieldCount; + ItoA itoa(_i++); + _b.appendBool(itoa, val); return *this; } BSONArrayBuilder& appendTimestamp(unsigned long long ts) { - _b.appendTimestamp(_fieldCount, ts); - ++_fieldCount; + ItoA itoa(_i++); + _b.appendTimestamp(itoa, ts); return *this; } @@ -937,7 +939,7 @@ public: return _b.len(); } int arrSize() const { - return _fieldCount; + return _i; } BufBuilder& bb() { @@ -945,7 +947,7 @@ public: } private: - DecimalCounter<uint32_t> _fieldCount; + std::uint32_t _i; BSONObjBuilder _b; }; diff --git a/src/mongo/bson/bsonobjbuilder_bm.cpp b/src/mongo/bson/bsonobjbuilder_bm.cpp deleted file mode 100644 index 53410f72615..00000000000 --- a/src/mongo/bson/bsonobjbuilder_bm.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/** - * Copyright (C) 2018 MongoDB Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * As a special exception, the copyright holders give permission to link the - * code of portions of this program with the OpenSSL library under certain - * conditions as described in each individual source file and distribute - * linked combinations including the program with the OpenSSL library. You - * must comply with the GNU Affero General Public License in all respects for - * all of the code used other than as permitted herein. If you modify file(s) - * with this exception, you may extend this exception to your version of the - * file(s), but you are not obligated to do so. If you do not wish to do so, - * delete this exception statement from your version. If you delete this - * exception statement from all source files in the program, then also delete - * it in the license file. - */ - -#include "mongo/platform/basic.h" - -#include <benchmark/benchmark.h> - -#include "mongo/bson/bsonobjbuilder.h" - -namespace mongo { - -void BM_arrayBuilder(benchmark::State& state) { - size_t totalBytes = 0; - for (auto _ : state) { - benchmark::ClobberMemory(); - BSONArrayBuilder array; - for (auto j = 0; j < state.range(0); j++) - array.append(j); - totalBytes += array.len(); - benchmark::DoNotOptimize(array.done()); - } - state.SetBytesProcessed(totalBytes); -} - -BENCHMARK(BM_arrayBuilder)->Ranges({{{1}, {100'000}}}); - -} // namespace mongo |