Bug/Feature Request: Arrays in types

BlitzMax Forums/BlitzMax Programming/Bug/Feature Request: Arrays in types

fredborg(Posted 2006) [#1]
Hi,

After spending a good 12 hours to find out why something sloved down on all secondary runs, I found the problem stemmed from the fact that I was using Arrays for type fields.

On the first run everything is snappy, but on all secondary runs the allocation slows down. Tests have indicated that the first run is as much as 150% faster than secondary runs.

Additionally it seems to slow down over time to some extent.

I have now replaced the array field with statics, but it does result in messier code, because I have to use pointers to index values in some situations.

Here's a simple example that should demonstrate the problem:

You will also notice that the first clean up from the array type takes an excessive amount of time.

I assume this is all related to the fact that arrays are completely dynamic, so the field with arrays assigned can be resized at will. My suggestion/feature resuest is that a static option is added to the arrays, so they cannot be resized, and therefore act as regular variables. Like this:
Field abc:Float[3] Static
Which would make the compiler lock down the size of the array at compile time.


marksibly(Posted 2006) [#2]
Hi,

Lack of static arrays is not a bug, although if you can provide some code that demonstrates 'slowing down over time' please post it in bug reports as that may well be.

The trouble with adding static arrays is simply that it introduces a whole new type to the system, along with issues such as 'what happens when you go t[]=p[]', 'what happens when you pass a static array to a function expecting a dynamic array? Can you? Vice versa?' and other related goodies.

Frankly, I'd rather concentrate on speeding up dynamic arrays.


fredborg(Posted 2006) [#3]
Ok, fair enough. But surely 35 seconds to clean up from the first run of the above code, is suspicious isn't it? It shouldn't take that long to free 1 million type instances.

I will post an example later that demonstrates the slowing down over time. It seems the above example doesn't suffer from it to the same extent.


Dreamora(Posted 2006) [#4]
I would assume that has to do with the counter-speedoptimal behavior of the GC which try to minimize the RAM usage instead the same way as "professional" GCs (C#, JAVA, Eiffel) work. (they do not minimize the usage ... there is no real reason for it, if there is free RAM anyway)

Found a similar behavior (but much worse on freeing - thought it was broken as it hadn't freed 5 mins later) when trying to find something that lets the GC fail. But that was influenced by strings in the list and this strings length as well. (you can do a simple while loop and add a string to a list until a given memory alloced border is reached. When doing with string = string + string it will need forever to clean, with string = string + "a" it will take quite long on first run as well but not nearly as worse as with the first version)


fredborg(Posted 2006) [#5]
Ok, it appears it's the garbage collector that slows down secondary runs. If I clean up manually, secondary runs are actually faster, but if I don't they are much slower.

It does look like the same applies to statics, but to a much lesser extent:



fredborg(Posted 2006) [#6]
Here's the original test, that caused my report: