ToSpread lag

Hey everyone,

I’m working on real-time texture generation from a spread of colors. Most of the time, this involves a relatively small spread (~15000 colors) to create a small texture (~300x50px). I use a SpreadBuilder to manipulate sub-spreads of colors, as suggested in the Gray Book. At the end of the process, I convert the SpreadBuilder to an immutable type via ToSpread and feed it to DynamicTexture2D.

One thing I’ve noticed is that I get periodic (literally) lags, even with this small amount of data. The larger the incoming spread, the more frequent the lag becomes. Removing ToSpread eliminates the lag completely, although that doesn’t seem to be the intended workflow for DynamicTexture2D:

Has anyone experienced a similar issue?

In this case ToSpread makes an unnecessary copy that just fills ram and puts burden on the garbage collector, which leads to the hickups you describe. The great thing about the DynamicTexture… nodes is that they allow you to connect a variety of collections and don’t require a Spread as input.

It would be interesting to understand what makes you feel that the version that works as intended is not the intended way of doing it?!

1 Like

Well, may be I got it wrong but I’ve read this in the Gray Book:

We would like to encourage you to use spread builders only locally: to create spreads. Pass around the spread that you just built. Don’t pass the builder itself. Even when you need to store a spread for later usage: store the spread, not the builder. It helps when reasoning about a patch.

To me that means that spread builders aren’t meant to be used directly outside spread manipulations (creating spreads, adding/removing items from spread e.t.c.).

Although passing spread builder in dynamic texture works (well, almost), I still see some obscure difference which is a bit hard to track - after some period of time dynamic texture stops updating itself. Moreover, this behaviour differs on different machines (on some of them it is almost never happens) I haven’t noticed such effect when I was feeding spread as an input. So, that brought me to that conclusion