Hello.
I will start with saying that our company uses Aspose.PSD to access TextLayers inside photoshop files, changing/replacing Portions from them, and other manipulations.
We have recently hit a situation where a particular document uses (in our opinion) way too much memory, and takes way too long to access every textLayers and change them, to the point where we have application crashing due to it.
I have made an experiment using versions 23.11, 24.6 and 24.7, and used a simple console app that
accesses said document 10 times, where each time it adds a new simple Portion to every single TexTLayer found inside it.
The code is as follows:
public static void Main()
{
SetupPathing();
for(int i = 0;i<10;i++)
{
TestPSD(i);
}
Console.Read();
}
private static void SetupPathing()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
psdFilePath = “/app/PSD.psd”;
psdSavePath = “/app/PSDSaveResult.psd”;
}
else
{
psdFilePath = “PSD.psd”;
psdSavePath = “PSDSaveResult.psd”;
}
}
private static void TestPSD(int index)
{
var image = Image.Load(psdFilePath);
PsdLicenser.LoadLicense();
if (image is PsdImage psdImage)
{
foreach (var layer in psdImage.Layers)
{
if (layer is TextLayer textLayer)
{
Stopwatch w = Stopwatch.StartNew();
var newPortion = textLayer.TextData.ProducePortions(
new[] { "adding text" },
null ,
null
).First();
textLayer.TextData.AddPortion(newPortion);
textLayer.TextData.UpdateLayerData();
w.Stop();
Console.WriteLine($"Portion added, time: {w}");
}
}
var imageOptions = new PsdOptions(psdImage);
psdImage.Save($"{psdSavePath}+{index}.psd" , imageOptions);
Console.WriteLine($"Document {psdSavePath}+{index}.psd saved.");
}
}
Running this code under docker linux, and also under windows, causes some textLayers to take even 10+ seconds to process, some more than 50 seconds sometimes under linux.
the memory under docker looks like this:
image.png (29.0 KB)
Runnin it on windows, i see the following:
image.png (16.1 KB)
I’m not sure what to call it, but the trend appears to be a memory leak somewhere caused by this document, or something of the sort.
Using other photoshop documents the trend is not visible, and works pretty much as we expected, but in this particular case, it does not.
Can you please check why/if this document is to blame? Or if you have any ideas for me to try, but currently, if this simple code sample is causing these issues, you can imagine what is happening when we further manipulate TextLayers in our application.
I have uploaded the document, as well as my DockerFile used in the app to test on linux with Docker:
https://drive.google.com/drive/folders/1lb2XPJsFYQ3f3cNGeBqeNEqrRthOUsox
Thank you and hope to hear from you soon!