Article View: comp.lang.tcl
Article #18Re: Experiment: inline bytecode for [lrange] with variable indices (written by Claude)
From: et99
Date: Thu, 08 Oct 2026 04:58
Date: Thu, 08 Oct 2026 04:58
38 lines
3869 bytes
3869 bytes
On 10/7/2026 12:25 PM, Olivier wrote:
>
> et99 <et99@rocketship1.me> posted:
>
>> Hi all:
>>
>> This experiment started as a side effect of a tool Claude and
>> I wrote to scan every proc in every package of a Magicsplat install,
>> looking for bytecode problems.
>>
>> Eric
>>
>
> Is your work something similar to Donal Fellows ("Optimizing Tcl Bytecode") ?
> I mean by supplying Donal Fellow's recommendations to Claude, it could
> improve something in Tcl speed, at least in the range of functionalities you have explored ?
>
> In fact I don't know if his work has been applied or not.
>
> Olivier.
Hi Olivier:
Short answer: kinda, I'm aware of Donal's peephole work in the core, and the assemble documentation has a section on it. But I imagine he's also working on other optimizations. My own scanning is a different thing, though. It's read-only analysis of compiled bytecode, not an optimizer.
It started with my calc tool (Colin's original = command). All the bytecode tools are unsupported, which is why I wrote TIP 760 to make assemble a supported command. To prepare, I had Claude read the assembler source and explain it to me.
One interesting find along the way: when a command's compile routine hits an error (for example [format %d notanumber] or [string is bogus x]), the compiler doesn't raise a script-level error. It bakes a "syntax" bytecode into the code, which I found in about 8 places in the source. The error only appears at run time, and only if that code is reached, so a mistake can sit dormant in production code for years.
So Claude and I wrote a scanner. Under Magicsplat, with its large package set, we loaded every package we could and used [info proc] to list every proc, since sourcing defines them without running them. Then we used disassemble/getbytecode to force all of them to compile, over 20k procs, and searched the bytecode for the syntax instruction. We found only 8 or 9.
I then added checks for patterns a peephole could optimize. One example is a temp variable whose bytecode could be dropped, but only when no trace or uplevel is in play, since either could need the temp to stay.
Next I looked for commands that were heavily used but not inlined, and found lrange. Since Claude can now build Tcl in his sandbox and test his own code, I asked him to inline it. He did, and he used validation tools I'd never heard of.
I'm having tons of fun with this. It may be my $20 a month level that makes it work so well, but it beats a cable subscription. :)
-eric
Technical Details
Message-ID:
<11a77uh$3gpfh$1@dont-email.me>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mailReferences:
<11a46mp$2f14b$1@dont-email.me> <1791401131-1108@newsgrouper.org>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: et99 <et99@rocketship1.me> Newsgroups: comp.lang.tcl Subject: Re: Experiment: inline bytecode for [lrange] with variable indices (written by Claude) Date: Wed, 7 Oct 2026 21:58:55 -0700 Organization: A noiseless patient Spider Lines: 38 Message-ID: <11a77uh$3gpfh$1@dont-email.me> References: <11a46mp$2f14b$1@dont-email.me> <1791401131-1108@newsgrouper.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Thu, 08 Oct 2026 04:58:58 +0000 (UTC) Injection-Info: dont-email.me; logging-data="3696113"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19tId+a2AFgEdmC0kpiQ2Pg"; posting-host="f99c1eab37cc5ad5c75580fd173b29c9" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:2VH3x4+CIMUl8DQXkpvkE7K1qVE= sha256:qMZfjzJcawqkfa9QgAoBgAGRbfGcCXblaX7qrzkWEU8= sha1:0gMtipnLgy8aCUGNC2xlvFpjiKQ= sha256:c7ow4y02PVejSMEodBFzXqJ5etha0f8lo0vi9vFAgg0= Content-Language: en-US In-Reply-To: <1791401131-1108@newsgrouper.org>