Skip to content

Commit

Permalink
unify init_haskell to allow nse profiling
Browse files Browse the repository at this point in the history
  • Loading branch information
dpwiz committed Mar 29, 2024
1 parent 7b644c0 commit 054ca81
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
6 changes: 1 addition & 5 deletions apps/ios/Shared/SimpleXApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ struct SimpleXApp: App {
init() {
DispatchQueue.global(qos: .background).sync {
// we have to use debug profile file name without extension here because .hp extension is added by profiler
haskell_init(
getAppEventLogPath().path,
getAppDebugProfilePrefixPath().path
)
// hs_init(0, nil)
haskell_init(0, getAppEventLogPath().path, nil)
}
UserDefaults.standard.register(defaults: appDefaults)
setGroupDefaults()
Expand Down
4 changes: 2 additions & 2 deletions apps/ios/SimpleX NSE/NotificationService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ func startChat() -> DBMigrationResult? {

startLock.wait()
defer { startLock.signal() }

if hasChatCtrl() {
return switch NSEChatState.shared.value {
case .created: doStartChat()
Expand All @@ -415,7 +415,7 @@ func startChat() -> DBMigrationResult? {

func doStartChat() -> DBMigrationResult? {
logger.debug("NotificationService: doStartChat")
haskell_init_nse()
haskell_init(1, nil, getAppDebugProfilePrefixPath().path)
let (_, dbStatus) = chatMigrateInit(confirmMigrations: defaultMigrationConfirmation(), backgroundMode: true)
logger.debug("NotificationService: doStartChat \(String(describing: dbStatus))")
if dbStatus != .ok {
Expand Down
31 changes: 24 additions & 7 deletions apps/ios/SimpleXChat/hs_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,29 @@

extern void hs_init_with_rtsopts(int * argc, char **argv[]);

void haskell_init(const char *eventlog, const char *heap_profile) {
void haskell_init(int nse, const char *eventlog, const char *heap_profile) {
// setup static arena for bump allocation and passing to RTS
char *argv[32] = {0,};
int argc = 0; // number of arguments used so far, always stands at the first NULL in argv
// common args
argv[argc++] = "simplex"; // fake program name
if (nse) {
argv[argc++] = "simplex-nse"; // fake program name
} else {
argv[argc++] = "simplex";
}
argv[argc++] = "+RTS"; // start adding RTS options
argv[argc++] = "-T"; // make GC counters available from inside the program
argv[argc++] = "-A64m"; // chunk size for new allocations (less frequent GC)
argv[argc++] = "-H64m"; // larger heap size on start (faster boot)
if (nse) {
argv[argc++] = "-S"; // spam stdout with GC stats
argv[argc++] = "-A1m"; // chunk size for new allocations (less frequent GC)
argv[argc++] = "-H2m"; // larger heap size on start (faster boot)
argv[argc++] = "-M12m"; // hard limit on heap
argv[argc++] = "-F0.5"; // heap growth triggering GC
argv[argc++] = "-Fd1"; // memory return
} else {
argv[argc++] = "-T"; // make GC counters available from inside the program
argv[argc++] = "-A64m"; // chunk size for new allocations (less frequent GC)
argv[argc++] = "-H64m"; // larger heap size on start (faster boot)
}
// argv[argc++] = "-M8G"; // keep memory usage under 8G, collecting more aggressively when approaching it (and crashing sooner rather than taking down the whole system)
if (eventlog) {
static char ol[1024] = "-ol";
Expand All @@ -34,8 +47,12 @@ void haskell_init(const char *eventlog, const char *heap_profile) {
argv[argc++] = po; // adds ".hp" extension
argv[argc++] = "-hT"; // emit heap profile by closure type
}
int non_moving_gc = !heap_profile; // not compatible with heap profile
if (non_moving_gc) argv[argc++] = "-xn";
if (nse) {
argv[argc++] = "-c"; // compacting garbage collector
} else {
int non_moving_gc = !heap_profile; // not compatible with heap profile
if (non_moving_gc) argv[argc++] = "-xn";
}
// wrap args as expected by RTS
char **pargv = argv;
hs_init_with_rtsopts(&argc, &pargv);
Expand Down
2 changes: 1 addition & 1 deletion apps/ios/SimpleXChat/hs_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#ifndef hs_init_h
#define hs_init_h

void haskell_init(const char *eventlog, const char *heap_profile);
void haskell_init(int nse, const char *eventlog, const char *heap_profile);

void haskell_init_nse(void);

Expand Down

0 comments on commit 054ca81

Please sign in to comment.