-
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 8 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,9 @@ | |
#import <FirebaseFirestore/FirebaseFirestore.h> | ||
|
||
#import <XCTest/XCTest.h> | ||
#include <mach/mach.h> | ||
|
||
#include <cstdint> | ||
|
||
#import "Firestore/Example/Tests/Util/FSTEventAccumulator.h" | ||
#import "Firestore/Example/Tests/Util/FSTIntegrationTestCase.h" | ||
|
@@ -323,4 +326,54 @@ - (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. | ||
std::int64_t GetCurrentMemoryUsedInMb() { | ||
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 std::int64_t memoryUsedBeforeCommitMb = GetCurrentMemoryUsedInMb(); | ||
XCTAssertNotEqual(memoryUsedBeforeCommitMb, -1); | ||
[batch commitWithCompletion:^(NSError *_Nullable error) { | ||
XCTAssertNil(error); | ||
const std::int64_t memoryUsedAfterCommitMb = GetCurrentMemoryUsedInMb(); | ||
XCTAssertNotEqual(memoryUsedAfterCommitMb, -1); | ||
const std::int64_t memoryDeltaMb = memoryUsedAfterCommitMb - memoryUsedBeforeCommitMb; | ||
// This by its nature cannot be a precise value. In debug mode, the increase on simulator | ||
// seems to be around 90 MB. 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.
Elsewhere we just call this type
int64_t
. The extra decoration is just noise.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.
I think we were previously using that because we were using
<stdint.h>
, but I don't feel too strongly about it.