godot
godot copied to clipboard
[3.5.1 Stable Mono] Extreme memory usage when using C# Dictionary for Web Export
Godot version
3.5.1.stable.mono
System information
Windows 10
Issue description
When exporting to web, C# Dictionary (Not to be confused with Godot's, this is the implementation from System.Collections.Generic) seems to take an extreme amount of memory, even when the content of the dictionary is minimal. It's unclear if this is just a performance issue or if its caused by memory leak.
The code snippet shown in the example takes ~3 seconds to run on my native OS, while on Web Export it crashed with an OutOfMemoryException exception.
Steps to reproduce
See minimal reproduction project
Minimal reproduction project
Open a blank project, create a scene and run this code snippet in _Ready()
var random = new Random();
var random_color = new Color[64];
for (int i = 0; i < 64; i += 1){
random_color[i] = new Color(i/64.0f, i/64.0f, i/64.0f);
}
for (int k = 0; k < 15; k += 1){
var ColorRequiredMap = new Dictionary<Color, int>();
for (int i = 0; i < 500000; i += 1){
var new_color = random_color[random.Next(64)];
if (!ColorRequiredMap.ContainsKey(new_color)){
ColorRequiredMap[new_color] = 1;
} else {
ColorRequiredMap[new_color] += 1;
}
}
}
Export to HTML Project and run.