Crunching BASIC - again
Vince M Hudd (116) 534 posts |
One of my occasional glances at the recent posts on the forum while still having a huge backlog of posts to read in my RSS client… In all this discussion of whether or not people should crunch or not (or include uncrunched versions), there does appear to be a subtlety in Steve’s original post that nobody has spotted – and, indeed, Steve’s replies doesn’t highlight the point AFAICS. I’ve added some emphasis to a couple of words:
If I’m reading that correctly, Steve isn’t talking about a cruncher that allows someone to distribute crunched BASIC. Instead, he seems to be suggesting one that works with BASALT to crunch programs only when they are run. Crunchie, while it saves crunched programs, is only to test his algorithms. Steve: Am I misunderstanding your comment? |
Steve Pampling (1551) 8172 posts |
When you have enough money and plenty to spare then more is just wasted. I suspect most modern RO machines are i/o bound rather than CPU bound and unless the crunching magically speeds up the access to the data files then it’s probably irrelevant. |
Jon Abbott (1421) 2651 posts |
Is there much use for them these days? They were traditionally used by games companies to obfuscate code or where you wanted to either reduce the size of the program to fit on an A3xx or gain a slight increase in speed. The later two were probably relevant on ARM2/3 but not so much on modern hardware. |
Steve Fryatt (216) 2105 posts |
The simple CRUNCH removed spaces and sped up execution a little; a full cruncher significantly reduced variable and FN/PROC name lengths, and distributed them around the alphabet to minimise the lengths of the lookup lists. ISTR this being noticeable on a RiscPC. I’ve no idea what the cumulative effect of the short names (less memory to step through during execution) and distributed initial characters actually is, or if it’s still relevant on modern machines. Personally, I’ve always linked LIBRARY code in to the main file when releasing applications, so have always crunched at the same time. I did consider writing a full name cruncher as part of Tokenize, but concluded that the effort required would probably far exceed the benefits on modern systems. |
Rick Murray (539) 13851 posts |
Fair point, but any competent BASIC coder would release:
Voilà, a nicely crunched program to distribute. ;-)
I believe bad-ass crunchers like StrongBS also did an amount of reworking of the program logic as well. To give you an idea – here’s the ToDo list of the StrongBS update, should it ever actually happen 1… https://sites.google.com/site/strongbsnow/to-do-list 1 Last update nearly a decade ago, and Google returns exactly zero matches for his email address between 2014/01/01 and now. |
Steve Drain (222) 1620 posts |
No. My motivation is to have Basalt crunch on loading, but that does not preclude having another approach with the same algorithms. The reactions here have been very interesting and I think everyone has supported the idea that crunched BASIC progams should not be distributed without the source. I would like to propose a couple of scenarios where that might not be best. The first is a commercial application, and how many of those written in C come with the source?. The second is a useful, complex application supported by an author who does not want modifications to be made, which might involve extra work. There are probably few of these, though. Assuming that the source is available, crunching is a free boost to a program that should not be dismissed out of hand, I think. Admittedly, a user may well not see much difference with most programs on modern machines. I started on a 16k Spectrum and I cannot shake the habit of looking for every saving of memory or gain in speed. It might be worth mentioning that BB4W always crunches programs to produce the runtime code. |
Clive Semmens (2335) 3276 posts |
Well put. I’m pretty sure that’s the case with all the apps I’ve written. The exceptions would be where a process grew more than linearly with data size, coupled with large data files – sorting huge files, for example. And then it would obviously be worth writing the heavily used core routines in Assembler. |
Clive Semmens (2335) 3276 posts |
8~) I can identify with that. I started on an 8k x 12bit PDP8… |
Steve Drain (222) 1620 posts |
Your actual scenario would not work – you could not use your method to take advantage of the way BASIC crunches programs run with -quit, for example. However, there are alternatives to achieve the same. I do not want to imply that I would ever want to prevent this – it just happens to be so. As an aside, a command to crunch in situ could also do other things to speed up a program, rather as BasaltInit does, and then it would be fruitless saving it out. ;-)
StrongBS does, but it looks more like a display of vituoso programming than making any real gains. The one thing that might help is concatening lines where possible. |
Rick Murray (539) 13851 posts |
Commercial applications are a different thing. People would want to protect their investment, especially given the very small market leads to software that may be seen as more expensive than elsewhere (it’s an economy of scale thing – a team of a dozen programmers looking to sell a million copies on Windows is really not the same thing as a single person selling copies with few zeros following the initial digit…). For software released “for free”, there is less justification for scrambling the code, other than what ultimately transpires to be a variation of “I’m ashamed of my code” or the like. Speed, as has been pointed out plenty above, is likely these days to be more down to how good the machine is at retrieving the data rather than the brute force of the processor. This isn’t to say that there’s no benefit in crunching the code, but more that the small speed gain is offset by rendering the software as a big black box that can’t be fiddled with if things go wrong (either due to program errors or changes in the underlying machine).
By and large, exactly zero. And for a commercial application, it would be unreasonable to expect it to be supplied with source while it is still being actively marketed and supported. Active commercial programs should be expected to be closed source. It’s the author’s revenue stream. But when the author moves on, said programs should have their source released in some manner. Think how much richer the RISC OS scene would be had this been the norm? We wouldn’t need products like Aemulor as various people could work on their favourite pet program to bring it to the 32 bit world.
I used to think like that, but Android has broken me. It’s good to be resource frugal rather than just treating memory as an endless dumping ground, but there are times when it just doesn’t make sense any more. It’s like why I, the author of the assembler tutorials (back in the Dark Ages when SWP was still A Thing), advocate knowing some assembly (it’s dead easy to make API calls with a couple of lines of in-line assembly) but I would never ever advocate writing an entire application in assembler unless you’re doing it to learn, to show off, or just for the lulz. Both GCC and Norcroft are competent compilers that produce good code. Except for low level system stuff, speed sensitive code, inline API calls, or to use facilities not (yet?) available in the compiler (such as NEON or ARMv8 stuff), there’s little justification for going the assembler route these days … unless, of course, you still code in BASIC where there isn’t much of an alternative for fast code. :-)
;-)
Tea → Keyboard. |
Steve Drain (222) 1620 posts |
That’s one alternative. Another is to extract the program from the application memory. ;-) |
Steffen Huber (91) 1953 posts |
Most of the time – at least for BASIC stuff – it does not make sense to provide the source code as a separate download anyway, this just leads to problems like “why is that website no longer available” or “where did I download that” or “what is this source that is lying around in my download directory”. You just put the source into the app dir. Only interested parties will ever see it, all others can safely ignore it. Since we don’t need to worry anymore to transport stuff on 800KiB floppies… |
Rick Murray (539) 13851 posts |
This.
This. Put the original code in a separate folder alongside the application, it highlights its presence. Put it inside the application, it doesn’t. Name it something like “Sourcecode”, it’ll be really obvious why that file is there. No confusion. Within the application itself, it is hidden in plain sight. There if necessary, yet pretty much invisible to non-geek users. |
Steve Pampling (1551) 8172 posts |
!AntiSpam – the source is tucked away like that. The edit and re(new) compress is simple. The general user doesn’t know, or care, that it is there. People who want to modify find it easy, not least because of the quantity of commenting. Of course it was developed by one person1 and further developed by another the latter would have been difficult with a cryptic ‘source’. 1 With assistance/hindrance from various others. |
John Sandgrounder (1650) 574 posts |
Talking of lost stuff. Does anyone have an un-crunched copy of !Usage? It would so much more use if we could fix the bug. |
John Williams (567) 768 posts |
You put a space after the dot! PS Which you seem to have just found out! |
John Sandgrounder (1650) 574 posts |
Yes. At long last. So, I edited the post to remove the PS! But thanks for the answer. |
John Sandgrounder (1650) 574 posts |
So, back to my original question …. …. Does anyone have an un-crunched copy of !Usage? |
Colin Ferris (399) 1818 posts |
What did you have in mind – Just run !Usage 1.01 (05-Sep2012) by Ran Mokady !runimage through !BasFormat to uncrunch it. |
David Pitt (3386) 1248 posts |
See !Usage 1.04 (18-Sep-15) from RC15. Looks OK on the RPi3 and Titanium. |
John Sandgrounder (1650) 574 posts |
I wanted to try to fix the bug in v1.03 which causes it to die with “too many nested structures”.
Thanks. But, I have not yet found a copy of !BasFormat.
Yes. the module seems to work OK. I think it is the Basic !RunImage which dies.
!Usage 1.03 Looks OK. But it eventually dies. I now have 1.04 running to see if that has the bug fixed. |
Jeffrey Lee (213) 6048 posts |
The uncrunched sources for Usage (and its helper module) are available in CVS. https://www.riscosopen.org/viewer/view/bsd/RiscOS/Sources/Utilities/Usage/ The VersionNum file (which is the main place to look for the change history) doesn’t mention any “too many nested structures” bug, so if you can find / fix the problem than that would be great. |
John Sandgrounder (1650) 574 posts |
uncrunched? Well, sort of. I suspect that the only bits that are uncrunched had to be re-written because even the author could not understand the original bits of code when they needed changing. Things like PROCa, FNb, j% etc are unintelligible. Never mind. It was worth asking. |
David Pitt (3386) 1248 posts |
There’s CRUNCH and there’s crunch. I have done a !BasFormat job on the compressed, crunched?, !RunImage so if or when the fault appears it should be easier to pin down, or not. |
John Sandgrounder (1650) 574 posts |
!Usage 1.04 dies in just the same way as 1.03 (“too many nested structures”), with a line number reference at the end of the file. I will have another look for the cause of the fault, but it will likely not be easy with code mostly crunched up. |