Open fthdgn opened 5 months ago
Thanks, nice find!
Looking at the diff, it appears the default value behaviour differs from the original and the two new branches.
String.init one does not have any value parameter. I am not sure purpose of that parameter. On my cases it unused. I will try to find a case where its value is essantial.
I found the usa case of value parameter. It is used when a language file does not provide translation for a key.
I used String.init(localized:defaultValue:table:bundle:locale:comment:)
function.
I detected very high memory usage on some screens of my app. I investigated the problem and found that the problem is
NSLocalizedString(_:tableName:bundle:value:comment:)
calls on R.swift.This PR replaces
NSLocalizedString(_:tableName:bundle:value:comment:)
calls withString.init(localized:table:bundle:locale:comment:)
on supported platforms.Benchmarks
Steps
MyStrings.string
Strings File (Legacy)MyStrings.string
tomy_key = "My Text";
ViewController.swift
to code below.ViewController.swift
and SPM package repo/commit to enable different scenariosResults
NSLocalizedString(_:tableName:bundle:value:comment:)
High is 52.5 MB. It was rising steadily until the timer is stopped.String.init(localized:table:bundle:locale:comment:)
High is 30.5 MB. It was 30 MB from the start to the end.R.string.myStrings.my_key()
formac-cain13/R.swift master 8d26021c6c71a513505e722f2cc82a6ad4f7f087
High is 57.3 MB. It was rising steadily until the timer is stopped.R.string.myStrings.my_key()
forfthdgn/R.swift nslocalizedstring-memory-leak 9f8f893d35f1d21e64abb8d991243099e3d5cdf0
High is 30.4 MB. It was around 30 MB from the start to the end.SwiftUI
SwiftUI has similiar results.
Text.init(_:tableName:bundle:comment:)
uses around 24 MB.Text(_:)
with inputNSLocalizedString(_:tableName:bundle:value:comment:)
's memory usage increases steadily.Text(_:StringResource)
from R.swift on master branch behaves likeNSLocalizedString
and memory usage keeps increasing.Text(_:StringResource)
from R.swift on this PR branch uses around 24 MB