Array scan challenge

This started out as a series of Advent challenges a couple of Christmases ago, but is now open for anyone to post challenges on any topic!
Richard Russell
Posts: 582
Joined: Tue 18 Jun 2024, 09:32

Re: Array scan challenge

Post by Richard Russell »

Richard Russell wrote: Tue 03 Feb 2026, 13:50 The question, of course, is whether this kind of 'micro optimisation' is sensible and whether I should update the release versions. What do you think?
So should I conclude that nobody cares? On the one hand in-lining the arithmetic operations in SUM() - and probably MOD() as well for consistency - will speed those operations up significantly. On the other, making the change will increase the size of the interpreter, perhaps by a few hundred bytes, which can impact cache efficiency and risk of introducing a bug.

Generally I'm not enthusiastic about micro-optimisation, but it is true that the whole-array operations in BBC BASIC are one of its most valuable (and unusual) features and if used with care can very significantly benefit performance. So a speed-up here can be argued to have a disproportionate benefit compared with its impact on the language as a whole.

And of course it could be argued that getting inconsistent results when rating submissions to a challenge is itself something worth addressing!
Richard Russell
Posts: 582
Joined: Tue 18 Jun 2024, 09:32

Re: Array scan challenge

Post by Richard Russell »

Richard Russell wrote: Wed 04 Feb 2026, 14:40 On the one hand in-lining the arithmetic operations in SUM() - and probably MOD() as well for consistency - will speed those operations up significantly.
To ensure that nobody is confused, can I remind you that we are talking about the coded-in-C versions of BBCSDL, i.e. the 64-bit and ARM versions. The coded-in-assembler versions, e.g. the Windows editions of BB4W and BBCSDL, are of course not affected in any way by this proposal, and I know of no way in which they could be speeded up.

If you want a really fast BBC BASIC then use Matrix Brandy BASIC which is somewhere between twice and five-times as fast as BBCSDL depending on the operation, and is available on most of the same platforms. Matrix Brandy shares many of the extensions with my BASICs (64-bit signed integers, 8-bit unsigned integers, the EXIT statement etc.).
Richard Russell
Posts: 582
Joined: Tue 18 Jun 2024, 09:32

Re: Array scan challenge

Post by Richard Russell »

Richard Russell wrote: Wed 04 Feb 2026, 17:06 To ensure that nobody is confused, can I remind you that we are talking about the coded-in-C versions of BBCSDL
Interestingly, this change appears to have no (measurable) effect at all on the in-browser (Web Assembly) edition. That makes me conclude that the Emscripten compiler and/or the Web Assembly ABI have a much more efficient way of passing a structure (actually a union) to a subroutine, greatly reducing the benefit of in-lining.