From a65154e0ad56c7200cdfe4cf7ac8c2bc673aeffb Mon Sep 17 00:00:00 2001 From: Eric Henderson Date: Wed, 30 Jul 2014 09:02:43 -0400 Subject: [PATCH] change auto-threshold to a different strategy --- README.md | 2 ++ Rakefile | 4 ++-- app/app_delegate.rb | 51 ++++++++++++++++++++++++++------------------- appcast.xml | 9 ++++++++ 4 files changed, 42 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 414996e..21b46af 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ A RubyMotion application for keeping memory usage in check. Shows up in the men * **v0.9:** New experimental feature: auto-threshold. Designed to automatically adjust your thresholds to the target frequency. If you try it out, please provide feedback at * **v0.9.1:** Make some changes to auto-threshold to hopefully improve it. If you try it out, please provide feedback at * **v0.9.2:** fix a bug introduced in v0.9.1 where memory threshold would be set to 0 if trim threshold was 0 +* **v0.9.3:** Auto-threshold has changed. My original design for it didn't turn out well, so I changed it to set the thresholds to a certain percent of post-freeing memory on a full freeing. Hopefully this will work better. ###Versions (code-signed with developer ID): * **v0.3:** (Mavericks-only) @@ -58,3 +59,4 @@ A RubyMotion application for keeping memory usage in check. Shows up in the men * **v0.9:** * **v0.9.1:** * **v0.9.2:** +* **v0.9.3:** diff --git a/Rakefile b/Rakefile index bec9370..f0525e3 100644 --- a/Rakefile +++ b/Rakefile @@ -27,8 +27,8 @@ Motion::Project::App.setup do |app| app.icon = 'Icon.icns' app.info_plist['CFBundleIconFile'] = 'Icon.icns' app.name = 'MemoryTamer' - app.version = '0.9.2' - app.short_version = '0.9.2' + app.version = '0.9.3' + app.short_version = '0.9.3' app.identifier = 'us.myepg.MemoryTamer' app.info_plist['NSUIElement'] = 1 app.info_plist['SUFeedURL'] = 'https://raw.githubusercontent.com/henderea/MemoryTamer/master/appcast.xml' diff --git a/app/app_delegate.rb b/app/app_delegate.rb index 8b687dc..cac991f 100644 --- a/app/app_delegate.rb +++ b/app/app_delegate.rb @@ -115,9 +115,9 @@ def applicationDidFinishLaunching(notification) @statusItem.setTitle(App::Persistence['show_mem'] ? format_bytes(cfm) : '') if App::Persistence['update_while'] || !@freeing diff = (NSDate.date - @last_free) diff_t = (NSDate.date - @last_trim) - mem_tweak_default('mem', cfm, dfm, [diff, diff_t + 30].min, 60*10, 60*15, 60*5, 60*10) - mem_tweak_default('trim_mem', cfm, dtm, diff_t, 60*5, 60*10, 60*3, 60*5) - App::Persistence['mem'] = [App::Persistence['mem'], App::Persistence['trim_mem']].min if App::Persistence['trim_mem'] > 0 && App::Persistence['auto_threshold'] != 'off' + # mem_tweak_default('mem', cfm, dfm, [diff, diff_t + 30].min, 60*10, 60*15, 60*5, 60*10) + # mem_tweak_default('trim_mem', cfm, dtm, diff_t, 60*5, 60*10, 60*3, 60*5) + # App::Persistence['mem'] = [App::Persistence['mem'], App::Persistence['trim_mem']].min if App::Persistence['trim_mem'] > 0 && App::Persistence['auto_threshold'] != 'off' set_mem_display if cfm <= dfm && diff >= 60 && diff_t >= 30 && !@freeing NSLog "seconds since last full freeing: #{diff}" @@ -133,25 +133,25 @@ def applicationDidFinishLaunching(notification) } end - def mem_tweak_default(var, cfm, dm, diff, low_min, low_max, high_min, high_max) - if (cfm < dm || diff > ((App::Persistence['auto_threshold'] == 'low' ? low_max : high_max) + 60)) && !@freeing - if App::Persistence['auto_threshold'] == 'low' - mem_tweak(var, diff, cfm, low_min, low_max) - elsif App::Persistence['auto_threshold'] == 'high' - mem_tweak(var, diff, cfm, high_min, high_max) - end - set_mem_display - set_trim_display - end - end - - def mem_tweak(var, diff, cfm, min, max) - if diff < min - App::Persistence[var] = (App::Persistence[var].to_f * [0.9, (diff.to_f / min.to_f)].max).ceil - elsif diff > max - App::Persistence[var] = (App::Persistence[var].to_f * [1.1, (diff.to_f / max.to_f)].min).ceil - end - end + # def mem_tweak_default(var, cfm, dm, diff, low_min, low_max, high_min, high_max) + # if (cfm < dm || diff > ((App::Persistence['auto_threshold'] == 'low' ? low_max : high_max) + 60)) && !@freeing + # if App::Persistence['auto_threshold'] == 'low' + # mem_tweak(var, diff, cfm, low_min, low_max) + # elsif App::Persistence['auto_threshold'] == 'high' + # mem_tweak(var, diff, cfm, high_min, high_max) + # end + # set_mem_display + # set_trim_display + # end + # end + # + # def mem_tweak(var, diff, cfm, min, max) + # if diff < min + # App::Persistence[var] = (App::Persistence[var].to_f * [0.9, (diff.to_f / min.to_f)].max).ceil + # elsif diff > max + # App::Persistence[var] = (App::Persistence[var].to_f * [1.1, (diff.to_f / max.to_f)].min).ceil + # end + # end def set_all_displays set_notification_display @@ -251,6 +251,13 @@ def free_mem_default(cfm) NSLog "Freed #{format_bytes(nfm - cfm, true)}" @freeing = false @last_free = NSDate.date + if App::Persistence['auto_threshold'] == 'low' + App::Persistence['mem'] = ((nfm.to_f * 0.3) / 1024**2).ceil + App::Persistence['trim_mem'] = ((nfm.to_f * 0.6) / 1024**2).ceil if App::Persistence['trim_mem'] > 0 + elsif App::Persistence['auto_threshold'] == 'high' + App::Persistence['mem'] = ((nfm.to_f * 0.5) / 1024**2).ceil + App::Persistence['trim_mem'] = ((nfm.to_f * 0.8) / 1024**2).ceil if App::Persistence['trim_mem'] > 0 + end end def trim_mem(cfm) diff --git a/appcast.xml b/appcast.xml index 5a3c20d..6264ae9 100755 --- a/appcast.xml +++ b/appcast.xml @@ -5,6 +5,15 @@ https://raw.githubusercontent.com/henderea/MemoryTamer/master/appcast.xml Most recent changes with links to updates. en + + Version 0.9.3 + + http://releases.io/henderea/MemoryTamer/0.9.3?heading=true + + Wed, 30 Jul 2014 9:05:00 -0400 + + 10.7 + Version 0.9.2