Comments (4)
By curiosity, how much data are you trying to mmap? i.e. how large is your realm file on disk?
from realm-swift.
Hey @jpsim, thanks for the quick response!
It looks like the realm file gets into some kind of locked state and keeps growing larger and larger while I'm inspecting it.
Started: 25KB
Reload same data (update or insert): 122KB
Keep loading page over and over (update or insert): 500KB
More (update or insert): 2MB
More: 12.6MB
More: 25.2MB
After 25.2MB it keeps climbing by itself (the app is not running) until it reached ~300MB (I deleted it at that point). I've attached some screenshots of the realm files I would download from the app bundle and inspect.
A little more context:
I'm importing the JSON into models (using an APIObject wrapped via CottonObject) in a background thread, each model has its own write transaction, and when the import is done I execute a completion block with the data on the main thread like this:
+ (User*) userWithAPIUser:(APIUser*)apiUser wrapTransaction:(BOOL)wrapTransaction
{
// get the default realm and try to find a user to update (else import new)
RLMRealm* realm = [RLMRealm defaultRealm];
User* user = nil;
RLMArray* matchingUsers = [User objectsWhere:@"id == %@",apiUser.id];
// write the user to the database
wrapTransaction ? [realm beginWriteTransaction] : 0;
user = matchingUsers.count ? matchingUsers.firstObject : [[User alloc] init];
user.id = apiUser.id.integerValue;
user.email = apiUser.email;
user.first_name = apiUser.first_name;
user.last_name = apiUser.last_name;
user.token = apiUser.token;
[realm addObject:user];
wrapTransaction ? [realm commitWriteTransaction] : 0;
// return the cached user
return user;
}
+ (NSArray*) usersWithAPIUsers:(NSArray*)apiUsers wrapTransaction:(BOOL)wrapTransaction
{
NSMutableArray* users = [NSMutableArray array];
for (APIUser* apiUser in apiUsers)
{
User* user = [User userWithAPIUser:apiUser wrapTransaction:wrapTransaction];
[users addObject:user];
}
return users;
}
+ (void) usersWithAPIUsers:(NSArray*)apiUsers
wrapTransaction:(BOOL)wrapTransaction
completion:(void(^)(NSArray* users))complete
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^
{
NSArray* users = [User usersWithAPIUsers:apiUsers wrapTransaction:wrapTransaction];
if (complete)
{
dispatch_async(dispatch_get_main_queue(), ^
{
complete(users);
});
}
});
}
I've browsed the schema via the Realm Browser and there aren't any duplicate entities either (the ones that exist just get updated). I apologize if I'm doing anything horribly wrong here, I'm more of an audio guy :P
from realm-swift.
Are you running this code passing int YES or No to wrapTransaction
? If you are constantly running through inserts/updates without ever closing a transaction you will end up using a huge amount of temporary disk space which will not get reclaimed until the transaction is closed. This might also explain the mmap issue. If you are using a single outer transaction (NO for wrapTransaction) then try passing in YES for wrapTransaction to see if that changes the behavior. I would also suggest using a single transaction in usersWithAPIUsers:wrapTransaction:
around each group of users rather than using a transaction for each user.
Also, when you dispatch back to the main queue, you are passing an array of RLMObjects which are associated with the RLMRealm instance on the background queue. There isn't currently a way to share objects across RLMRealm instances/threads so for now you need fetch the objects on the main thread after a change. Instead of dispatching back to the main thread you can instead register for a notification and respond in kind to any changes.
from realm-swift.
This was probably related to #709 which we fixed earlier this morning, per the ML
from realm-swift.
Related Issues (20)
- baseUrl Change
- Crash in app launch ios 14 and earlier HOT 4
- @AutoOpen doesn't work HOT 1
- Repeative Crash HOT 9
- Crash when launch HOT 9
- Crash with in query when comparing with empty collection
- Sectioned Results with Empty Sections HOT 5
- Realm-swift is utilising 100-150% CPU when in background HOT 3
- Crashed: Realm Notification Listener (BACKGROUND) HOT 9
- Error InvalidSession on logout after delete user HOT 7
- Crash - Assertion failed: m_lock_info && m_lock_info->m_file.get_path() == m_filename HOT 5
- Crash in Realm Sync, realm::SyncSession::handle_location_update_failed, realm_core_v_13_26_0 HOT 11
- Building with cocoapods produces warning about duplicate libraries - "-lc++" HOT 1
- realm-monorepo.xcframework & required reason API usage HOT 2
- Update default base URL to new domain HOT 1
- Possible perf regression between 10.42.3 and 10.47.0 HOT 6
- "Decryption failed" errors immediately after compacting two Realm files on startup HOT 5
- Create a GHA workflow to upload core prebuilds to S3 HOT 1
- Swift UI Previews are crashing in Xcode 15.3 (worked fine in 15.2). HOT 6
- Crash when user sessions are revoked HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from realm-swift.