ãã¹ããã©ã¯ãã£ã¹ã¬ã¤ãã® Strings and text ã®å 容ãæ¥æ¬èªã§ç´¹ä»
æååã¨ããã¹ã
Unity ããã¥ã¡ã³ããã¹ããã©ã¯ãã£ã¹ã¬ã¤ã( Best practice guides )ã® Strings and text ã®å 容ãæ¥æ¬èªã§ç´¹ä»ã
Unity - Manual: Strings and text
https://docs.unity3d.com/Manual/BestPracticeUnderstandingPerformanceInUnity5.html
- æååé£çµã¯ StringBuilder ã使ã
â»ãã㯠Unity ã«éãã C# ããã°ã©ã ã§ããè¨ãããäºã§ããã s += "abc" ãªã©ã¨ããã¨å é¨çã«ã¯æ°ãã string ãçæãããå¦çãèµ°ãã®ã§ã³ã¹ããå¢ããã®ã§ãã¡ã£ã¦ãã¤ã§ãã
ãã±ã¼ã«å¼·å¶ã¨é åºæ¯è¼
- String.Equals() ã¯ãã±ã¼ã«ãèæ ®ããå¦çãè¡ãããã®ã§æ³¨æ
ä¾ãã°ä»¥ä¸ã®æ§ã« pe ã®é¨åãå¾®å¦ã«ç°ãªãæååãæ¯è¼ãã¦ãã¾ãããã±ã¼ã«ã US-English ã®å ´åã«ã¯ true ãè¿ãã¾ããã¨ã¼ãããã®ãã±ã¼ã«ãè¨å®ããã¦ããå ´åã«ã¯ false ãè¿ãããã§ãã
â»ã¤ã¾ãå
é¨ã§è¤éãªå¦çãè¡ããã¦ããã
String.Equals("encyclopedia", âencyclopædiaâ);
æ³¨ï¼ Unity ã¯ãã¼ã¸ã§ã³ 5.3 㨠5.4 ã®æç¹ã§ã Unity ã®ã¹ã¯ãªããã£ã³ã°ã©ã³ã¿ã¤ã ã¯å¸¸ã«è±èªï¼US-enï¼ãã±ã¼ã«ã§å®è¡ãããã
ã»ã¨ãã©ã®æååæ¯è¼ã§ã¯ C ã C++ ã¨åæ§ã®æ¯è¼ã§åé¡ç¡ãå ´åãå¤ãããã®æ§ãªæ¯è¼ã¯ StringComparison.Ordinal ã§å®ç¾å¯è½ã
myString.Equals(otherString, StringComparison.Ordinal);
ãæååæ¤ç´¢å¦çã®ãã³ããã¼ã¯çµæã
Method | Time (ms) for 100k short strings |
---|---|
String.StartsWith, default culture | 137 |
String.EndsWith, default culture | 542 |
String.StartsWith, ordinal | 115 |
String.EndsWith, ordinal | 34 |
Custom StartsWith replacement | 4.5 |
Custom EndsWith replacement | 4.5 |
cultureï¼ã«ã«ãã£ã¼ããã±ã¼ã«)ã使ã£ãæãä¸çªé ãã使ããªãã£ãæããããããCustomï¼èªåã§æºåããå ´å)ãä¸çªé«éã¨ããçµæã
EndsWith 㨠StartsWith ã®ã«ã¹ã¿ã ã¡ã½ããã®ä½ä¾ã
public static bool CustomEndsWith(string a, string b) { int ap = a.Length - 1; int bp = b.Length - 1; while (ap >= 0 && bp >= 0 && a [ap] == b [bp]) { ap--; bp--; } return (bp < 0 && a.Length >= b.Length) || (ap < 0 && b.Length >= a.Length); } public static bool CustomStartsWith(string a, string b) { int aLen = a.Length; int bLen = b.Length; int ap = 0; int bp = 0; while (ap < aLen && bp < bLen && a [ap] == b [bp]) { ap++; bp++; } return (bp == bLen && aLen >= bLen) || (ap == aLen && bLen >= aLen); }
æ£è¦è¡¨ç¾
- ã·ã³ãã«ãª IsMatch ã§ããå é¨å¦çã§å¤§ããªãã¼ã¿å²å½ã¦ãèµ°ãçºãåæåä¸ãé¤ãã¦è¨±å®¹ã§ããªãã¨èããã¹ãã
- Regex.Match ã Regex.Replace ãªã©ã®éçã¡ã½ããã¯ãªã³ã¶ãã©ã¤ã§æ£è¦è¡¨ç¾ãã³ã³ãã¤ã«ããçæããããªãã¸ã§ã¯ãããã£ãã·ã¥ããªãã®ã§å¼·ãéæ¨å¥¨ã
ä¾)
Regex.Match(myString, "foo");
ããã¯å®è¡ãããã³ã«5KBã®ã´ã(ã¬ãã¼ã¸ã³ã¬ã¯ã·ã§ã³ã®å¯¾è±¡ã«ãªããã®)ãçºçã
var myRegExp = new Regex("foo");
myRegExp.Match(myString);
ãã®å ´åã¯320ãã¤ãã®ã´ããçºçã
XMLãJSONããã®ä»ã®é·æããã¹ãã®è§£æ
- å¤ãã®ãµã¼ããã¼ãã£ã¼ã®ãã¼ãµã¼ã¯ããªãã¬ã¯ã·ã§ã³ã«åºã¥ãã¦æ§ç¯ããã¦ããããªãã¬ã¯ã·ã§ã³ã¯éçºä¸ã«åªããé¸æè¢ã§ããï¼ãã¼ãµããã¼ã¿ã¬ã¤ã¢ã¦ãã®å¤æ´ã«è¿ éã«å¯¾å¿ã§ããããï¼ãé ãã
- Unity ã¯ãã®è§£æ±ºçã¨ã㦠JSONUtility API ãæºåã
- ããã¯ç´ç²ãª C# JSONãã¼ãµãããéãã
- 追å ã³ã¼ããªãã§è¾æ¸ãªã©å¤ãã®è¤éãªãã¼ã¿åãã·ãªã¢ã©ã¤ãºãããã¨ã¯ã§ããªãã
代æ¿æ¡ã¯ä»¥ä¸ã®3ã¤
1:ãã«ãæã«è§£æãã
ãã¼ã¿ã ScriptableObject ã«ç§»åãã AssetBundle ãä»ãã¦é
å¸ããã
ãã®è¾ºãã®è©±ã«ã¤ãã¦ã¯ä»¥ä¸ã®åç»(è±èª)ãåç
§
ãã®æ¦ç¥ã¯å¯è½ãªéãæè¯ã®ããã©ã¼ãã³ã¹ãæä¾ããããåçã«çæããå¿
è¦ã®ãªããã¼ã¿ã«ã®ã¿é©ãã¦ãããã²ã¼ã ãã¶ã¤ã³ã®ãã©ã¡ã¼ã¿ããã®ä»ã®ã³ã³ãã³ãã«æé©ã
2:ã¹ããªããããã³é 延ãã¼ã
解æãã¹ããã¼ã¿ãå°ããªåä½ã«åå²ããå¿ è¦ã«ãªã£ãæç¹ã§ãã¼ããããã
3:ã¹ã¬ãã
å®å
¨ã« C# ã®ãªãã¸ã§ã¯ããã使ç¨ããã Unity API ã使ç¨ããªãå ´åã«ã¯ã解ææä½ãã¯ã¼ã«ã¼ã¹ã¬ããã«ç§»ãäºãã§ããã
ã¹ã¬ããã使ç¨ããå ´åã«ä½¿ç¨ããã¯ã©ã¹ã¯ Thread ã ThreadPool ã
Thread ã¯ã©ã¹ (System.Threading)
https://msdn.microsoft.com/ja-jp/library/system.threading.thread%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396
ThreadPool ã¯ã©ã¹ (System.Threading)
https://msdn.microsoft.com/ja-jp/library/system.threading.threadpool(v=vs.110).aspx
æ¹æ³ : ã¹ã¬ãããä½æããã³çµäºãã (C# ããã°ã©ãã³ã° ã¬ã¤ã)
https://msdn.microsoft.com/ja-jp/library/7a2f3ay4(v=vs.90).aspx