-
Notifications
You must be signed in to change notification settings - Fork 1.6k
In FSTLocalDocumentsView, search for all batches affecting a set of keys in one go #1505
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
Changes from 3 commits
c6c2a9c
76bf96a
36d8596
b70157c
19d862a
8283a7b
7f0c933
06dad9b
7b366a1
e29283f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
#import <FirebaseFirestore/FirebaseFirestore.h> | ||
|
||
#import <XCTest/XCTest.h> | ||
#include <mach/mach.h> | ||
|
||
#import "Firestore/Example/Tests/Util/FSTEventAccumulator.h" | ||
#import "Firestore/Example/Tests/Util/FSTIntegrationTestCase.h" | ||
|
@@ -323,4 +324,53 @@ - (void)testUpdateNestedFields { | |
[self awaitExpectations]; | ||
} | ||
|
||
// Returns how much memory the test application is currently using, in megabytes (fractional part is | ||
// truncated), or -1 if the OS call fails. | ||
// TODO(varconst): move the helper function and the test into a new test target for performance | ||
// testing. | ||
long long getCurrentMemoryUsedInMb() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: there is also something like performance tests in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, free functions should start with an initial capital. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
mach_task_basic_info taskInfo; | ||
mach_msg_type_number_t taskInfoSize = MACH_TASK_BASIC_INFO_COUNT; | ||
const auto errorCode = | ||
task_info(mach_task_self(), MACH_TASK_BASIC_INFO, (task_info_t)&taskInfo, &taskInfoSize); | ||
if (errorCode == KERN_SUCCESS) { | ||
const int bytesInMegabyte = 1000 * 1000; | ||
return taskInfo.resident_size / bytesInMegabyte; | ||
} | ||
return -1; | ||
} | ||
|
||
- (void)testReasonableMemoryUsageForLotsOfMutations { | ||
XCTestExpectation *expectation = | ||
[self expectationWithDescription:@"testReasonableMemoryUsageForLotsOfMutations"]; | ||
|
||
FIRDocumentReference *mainDoc = [self documentRef]; | ||
FIRWriteBatch *batch = [mainDoc.firestore batch]; | ||
|
||
// >= 500 mutations will be rejected, so use 500-1 mutations | ||
for (int i = 0; i != 500 - 1; ++i) { | ||
FIRDocumentReference *nestedDoc = [[mainDoc collectionWithPath:@"nested"] documentWithAutoID]; | ||
// The exact data doesn't matter; what is important is the large number of mutations. | ||
[batch setData:@{ | ||
@"a" : @"foo", | ||
@"b" : @"bar", | ||
} | ||
forDocument:nestedDoc]; | ||
} | ||
|
||
const long long memoryUsedBeforeCommitMb = getCurrentMemoryUsedInMb(); | ||
XCTAssertNotEqual(memoryUsedBeforeCommitMb, -1); | ||
[batch commitWithCompletion:^(NSError *_Nullable error) { | ||
XCTAssertNil(error); | ||
const long long memoryUsedAfterCommitMb = getCurrentMemoryUsedInMb(); | ||
XCTAssertNotEqual(memoryUsedAfterCommitMb, -1); | ||
const long long memoryDeltaMb = memoryUsedAfterCommitMb - memoryUsedBeforeCommitMb; | ||
// This by its nature cannot be a precise value. A regression would be on the scale of 500Mb. | ||
XCTAssertLessThan(memoryDeltaMb, 150); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this the same for both 32 and 64-bit builds? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried it using two simulators in debug mode:
I don't have a real device handy, but I can try to find one if you'd like. |
||
|
||
[expectation fulfill]; | ||
}]; | ||
[self awaitExpectations]; | ||
} | ||
|
||
@end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should avoid
long long
. Probably this can beint64_t
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.