Skip to content

Huge Memory Consumtion #14

@adamfur

Description

@adamfur

Created a dotnet 5 project with the nuget reference, the application consumed 70MiB RSS memory.

static async Task Main(string[] args)
{
    while (true)
    {
        Console.WriteLine(Guid.NewGuid().ToString().Unidecode());
        await Task.Delay(TimeSpan.FromSeconds(1));
    }
}

Thought it was quite a lot of memory for such a small library, created a new dotnet 5 project with a project
reference to the source code of the master branch, and the application consumed 200 MiB RSS memory???
Removed the partial (Diff below) and the RSS memory shrunk down to 5 MiB RSS.

diff --git a/src/Unidecoder.Characters.cs b/src/Unidecoder.Characters.cs
index dd8cdac..3b4d792 100644
--- a/src/Unidecoder.Characters.cs
+++ b/src/Unidecoder.Characters.cs
@@ -27,11 +27,11 @@ using System.Collections.Generic;
 
 namespace Unidecode.NET
 {
-    public static partial class Unidecoder
+    public static class Unidecoder2
     {
-        private static readonly Dictionary<int, string[]> characters;
+        public static readonly Dictionary<int, string[]> characters;
 
-        static Unidecoder()
+        static Unidecoder2()
         {
             characters = new Dictionary<int, string[]> {
                 {0 /*0 000*/, new[]{
@@ -605,4 +605,4 @@ namespace Unidecode.NET
             }
         }
     }
-    
\ No newline at end of file
+    
diff --git a/src/Unidecoder.cs b/src/Unidecoder.cs
index 558c725..1e1653e 100644
--- a/src/Unidecoder.cs
+++ b/src/Unidecoder.cs
@@ -6,7 +6,7 @@ namespace Unidecode.NET
     /// <summary>
     /// ASCII transliterations of Unicode text
     /// </summary>
-    public static partial class Unidecoder
+    public static class Unidecoder
     {
         /// <summary>
         /// Transliterate Unicode string to ASCII string.
@@ -42,7 +42,7 @@ namespace Unidecode.NET
                 {
                     var high = c >> 8;
                     var low = c & 0xff;
-                    if (characters.TryGetValue(high, out var transliterations))
+                    if (Unidecoder2.characters.TryGetValue(high, out var transliterations))
                     {
                         sb.Append(transliterations[low]);
                     }
@@ -71,7 +71,7 @@ namespace Unidecode.NET
             {
                 var high = c >> 8;
                 var low = c & 0xff;
-                result = characters.TryGetValue(high, out var transliterations) ? transliterations[low] : "";
+                result = Unidecoder2.characters.TryGetValue(high, out var transliterations) ? transliterations[low] : "";
             }
 
             return result;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions