Download

HELP: Splitting string of numbers into array of integers. slow.

I want to split a large string of 10000 numbers into an array of 10000 integers.
At the moment I am doing it like this in my blueprint. This is very slow. It cause my editor to freeze for 30 seconds.


I can do this kind of thing with C# in unity very fast, why is it so slow in my blueprint?
Thanks

2 points:

  1. why are you accessing the array again in order to get the added number? You already have direct access to it: just connect “Array Element” to “Print String”, no need of GET.
  2. you want even more speed, then remove the print string altoghether.

So, remove print string and GET and you will increase the speed.

do you mean to say I should not re-build the string array into an int array, and just convert the strings to ints as and when they are neded?

Print string is very slow. Blueprint is also slower than C#.

Rather than printing the results every loop, try to print the result of that after the loop is complete in a separate method. I assume your end product won’t need to just convert > convert > print :slight_smile:

Right now you’re going into the VM layer 100k times for all this conversion from string to int to string again on every loop and the print string doesn’t help. Also if you know how to code this in C#, coding it in C++ is not much different, really.



for (int32 i = 0; i < ParsedString.Num(); i++)
{
    IntsArr.Add(FCString::Atoi(*ParsedString*));
}


Ah right thanks, i see what you mean. For printing, i should assemble what i want to print, and then just call print once.

This is a bit offtopic, but it might be a similar kind of problem: I have wanted to assemble an image based on an array of numbers. I tried to draw each number in the array to a canvas rendertarget, however this was also extremely slow. Would you know anything about that?

Honestly, not my area of expertise :slight_smile: But you might create a smaller render target to fit one number and render it to a PNG then assemble all of the PNGs in sequence. That would be faster than filling out a large Render Target up to a point (like over 2k).

As mentioned, blueprints are slow.
But there’s a big optimization you could do to the setup in your picture, and that is to save the array that the Parse Into Array returns into a local variable, and iterate over that instead.
Because with pure nodes, they are executed every time you access them. And every new loop accesses the Parse, forcing it to perform its operation on the string every single time.

That might actually make a big difference.