Skip to content

Add Google Benchmark library and benchmark leveldb #1137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Jul 20, 2018

Conversation

gsoltis
Copy link

@gsoltis gsoltis commented Apr 18, 2018

Adds benchmark capability. Includes a benchmark of leveldb writes with and without index writes. The test is currently disabled to avoid running by default.

Copy link
Contributor

@wilhuff wilhuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool!

See below for an alternative arrangement that doesn't require checking in dead code.


- (void)testRunBenchmarks {
// Enable to run benchmarks.
if (false) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably better captured as an early return so that this thing ends up written at a normal indent.

Also a better way to make this work is to create a new Benchmarks_iOS target within the project and add this test to that target instead of Firestore_Tests. That way we don't have to edit the files to run the benchmarks and they naturally exclude themselves during normal work.

@wilhuff wilhuff assigned gsoltis and unassigned wilhuff Apr 20, 2018
@gsoltis
Copy link
Author

gsoltis commented Jul 19, 2018

Ok, I made a separate target and it runs the benchmarks. No more dead code. PTAL.

@gsoltis gsoltis assigned var-const and wilhuff and unassigned gsoltis Jul 19, 2018
Copy link
Contributor

@wilhuff wilhuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically LGTM

@@ -709,6 +743,7 @@
6003F5B5195388D20070C39A /* Tests */,
54764FAC1FAA0C390085E60A /* CoreTests */,
54C9EDF22040E16300A969CD /* SwiftTests */,
5CAE131A20FFFED600BE9A4A /* Firestore_Benchmarks_iOS */,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could rename this in the left-hand nav to just "Benchmarks"?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

*/

#import <Foundation/Foundation.h>
#import "../../../../../../../Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Frameworks/XCTest.framework/Headers/XCTest.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be <XCTest/XCTest.h>.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

target 'Firestore_Benchmarks_iOS' do
inherit! :search_paths

pod 'GoogleBenchmark', :podspec => 'Tests/GoogleBenchmark/GoogleBenchmark.podspec'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put this podspec just directly within Firestore/Example (like ProtobufCpp and GoogleTest above).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

'include/benchmark/*.h'
]

s.pod_target_xcconfig = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if you add "${PODS_ROOT}/GoogleBenchmark/include" to pod_user_config you won't have to manually configure that.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving this as-is. The other setting did not work, and this currently matches GoogleTest.

@wilhuff wilhuff assigned gsoltis and unassigned var-const and wilhuff Jul 19, 2018
Copy link
Contributor

@var-const var-const left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some optional nitpicks (feel free to ignore), otherwise LGTM.

*/

#import <Foundation/Foundation.h>
#import "../../../../../../../Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Frameworks/XCTest.framework/Headers/XCTest.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be just #import <XCTest/XCTest.h>; or similar?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -18,6 +18,11 @@ target 'Firestore_Example_iOS' do
pod 'GoogleUtilities', :path => '../../'
pod 'FirebaseFirestore', :path => '../../'

# pod 'leveldb-library'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this commented-out code be removed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}

s.library = 'c++'
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ultranit: add a newline at the end of the file, so that Github doesn't display the annoying red symbol?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

using firebase::firestore::model::DatabaseId;

// Pre-existing document size
static const int kDocumentSize = 1024 * 2; // 2 kb
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional nit: instead of using static variables and functions, consider wrapping them in an anonymous namespace. It achieves the same thing, but is slightly less verbose, and has the advantage of working being more universal (static cannot be applied to class/struct).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}

static NSString *LevelDBDir() {
NSError *error;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional nit: move error closer to the point of usage, in the if statement scope?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

_emptyBuffer);
}

FSTLevelDB *_db;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what the rules are for a pointer to an Objective-C object. A regular pointer would be uninitialized, so I'd suggest setting it to nullptr. However, perhaps this pointer is set to nil automatically?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is automatically nil: https://stackoverflow.com/a/9072040

// In each test, either overwrite index entries and documents, or just documents

BENCHMARK_DEFINE_F(LevelDBFixture, RemoteEvent)(benchmark::State &state) {
bool writeIndexes = (bool)state.range(0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional nit: use static_cast<bool> instead of C-style conversion, it's easier to spot, greppable, and it's more clear what it does (C-style cast is much more powerful than a static_cast, which may lead to surprising unintended conversions, especially when code is modified later on).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

BENCHMARK_DEFINE_F(LevelDBFixture, RemoteEvent)(benchmark::State &state) {
bool writeIndexes = (bool)state.range(0);
int64_t documentSize = state.range(1);
int64_t docsToUpdate = state.range(2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: add #include <cstdint>;?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

bool writeIndexes = (bool)state.range(0);
int64_t documentSize = state.range(1);
int64_t docsToUpdate = state.range(2);
std::string documentUpdate = UpdatedDocumentData((int)documentSize);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same optional nit about casting. Or perhaps just modify UpdatedDocumentData to accept an int64_t? There doesn't seem to be a need for divergence.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

int64_t documentSize = state.range(1);
int64_t docsToUpdate = state.range(2);
std::string documentUpdate = UpdatedDocumentData((int)documentSize);
for (auto _ : state) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make the loop variable a const reference? for (const auto& _ : state) {. While _ variable is not used, copies are still being made. I don't know what state contains, but presumably these are objects larger than a couple of ints (otherwise, just leave as is).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

@var-const var-const left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing the changes!

Copy link
Contributor

@wilhuff wilhuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@gsoltis gsoltis merged commit 3b939a2 into master Jul 20, 2018
@gsoltis gsoltis deleted the gsoltis/benchmark_leveldb branch July 20, 2018 02:44
@firebase firebase locked and limited conversation to collaborators Nov 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants