Isn't 100 elems a bit much space for the default OSC bundle size?

I noticed

+SequenceableCollection {

	asOSCArgBundle {
		var array = Array(100);		// allocate a bunch of space

This is in SCClassLibrary\Common\Control\extConvertToOSC.sc Isn’t this a bit much space allocated by default for a bundle though? (That’s in a common code path, called e.g. from Event type \set, not of one of those disused but still around OSC code paths.)

If it starts with an empty array, then it will have to expand at powers of two beyond 4. “Expand” means allocating a new array at the next size and leaving the old one to the garbage collector.

So the choice is to garbage collect one array which probably hasn’t used all its slots, or to garbage collect multiple arrays of various sizes.

I don’t think we ever benchmarked but we’re guessing that garbage-collecting the single large array is less expensive than the alternative.

hjh

Is there a reason why the size of the SequenceableCollection itself isn’t/can’t be used a size hint for the OSC array?

“Isn’t it a bit much space”… “Is there a reason why”… :flushed:

Anyway, you could investigate the performance of that.

(
~makeFunc = { |sizeHint|
	f = { |n = 1|
		var out = Array(sizeHint.value(n));
		n.do { out = out.add(0) };
		out
	};
};
)

f = ~makeFunc.(100);
bench { 50000.do { f.value(rrand(6, 80)) } };
time to run: 0.40493041299999 seconds.
time to run: 0.40351290199999 seconds.
time to run: 0.38673588699999 seconds.

f = ~makeFunc.(4);
bench { 50000.do { f.value(rrand(6, 80)) } };
time to run: 0.40597682199999 seconds.
time to run: 0.42796979899998 seconds.
time to run: 0.40106156599998 seconds.

f = ~makeFunc.({ |n| n });
bench { 50000.do { f.value(rrand(6, 80)) } };
time to run: 0.36153494199999 seconds.
time to run: 0.36399645699998 seconds.
time to run: 0.363490724 seconds.

So, if there are no arrayed controls, it is faster to initialize to Array(n).

But if there are arrayed controls, performance is worse than initializing to 100.

(
~makeFunc = { |sizeHint|
	f = { |n = 1|
		var out = Array(sizeHint.value(n));
		(n + 2).do { out = out.add(0) };
		out
	};
};
)

f = ~makeFunc.({ |n| n });
bench { 50000.do { f.value(rrand(6, 80)) } };
time to run: 0.38473991000001 seconds.
time to run: 0.41132203400002 seconds.
time to run: 0.41062956899998 seconds.

hjh

1 Like