Skip to content
Tcl Source Code Check-in [23da210385]
Login

Check-in [23da210385]

Overview
Comment:I have updated `bench_cstruct.tcl` and re-run it on v16e: in compact mode, the full sequence runs 15 times faster than standard Tcl. However, two metrics showed a regression: `lassign $it(*)` and the object-oriented approach. The script: The library: it loads `cstruct[info sharedlibextension]` in both modes—so, `cstruct.dll` on your system. Two new metrics: 5c: fields read directly within `expr` (e.g., `$it(value) < $mn`), which v16c accelerates. 5d: tuple-style assignment `(id, v, fl) = $it`, which v16e accelerates. Verification: before taking measurements, the script checks that all three calculation methods yield the same result. Compact mode: measured by running `TCL_TYPES_COMPACT=1 tclsh bench_cstruct.tcl annote`. Measurements (in µs, based on a batch of 10,000 items, on Linux, over two runs): Step Annotated Annotated, compact Standard Tcl Encoding 1,150 255 to 340 4,100 to 4,200 Decoding 3,400 127 to 163 8,000 to 9,400 Full sequence `cs::stats` 1,600 270 to 280 4,000 to 4,600 (raw) 8,600 to 8,800 (checked) Calculation $it(field) / in expr: 3,800 / 3,700 | 3,900 / 3,700 to 5,300 | 2,800 to 3,300 (lassign) Calculation by tuple: 7,500 to 9,100 | 5,800 to 6,300 | — Calculation lassign $it(*): 15,300 | 15,400 to 17,200 | — Object-oriented path cs::stats_obj: 2,400 to 2,800 | 2,500 to 2,700 | — In the compact format, encoding and decoding simply involve copying the cells. Decoding is 60 times faster than `binary scan`, and the entire string operation is 30 times faster than the classic checked approach. Two regressions: `lassign $it(*)` takes 15 ms, compared to 7–9 ms in the previous implementation. Reading all parts via `$it(*)` goes through the general path-handling logic—taking approximately 2.4 µs, versus 0.7 µs for a single field. A shortcut for a typed product would resolve this. The object-oriented path has gone from 0.5 ms to 2.4 ms since v15. It currently requests the batch content from Tcl via the interpreter, then re-reads each field. Rewriting `cstruct.c` using `tclAnnotatedApi.h` and `Tcl_AnnotatedGetCells`—similar to `geo.c`—would allow it to read the cells directly from the compact format. This would require recompiling `cstruct.dll`. In this benchmark, calculation by tuple remains twice as slow as individual field reads. It incurs the cost of three variable writes and content extraction at each measurement, whereas `$it(field)` reads take advantage of the field cache. The “v16e” section of the `README.md` for `cstruct` provides this table and these analyses.
Timelines: family | ancestors | descendants | both | tip-764_tcl90
Files: files | file ages | folders
SHA3-256: 23da210385efb3eecaa72196ae41b46061e01d6ef2ebed7a9034e2cc806e300f
User & Date: Florentis on 2026-10-25 13:02:55.812
Other Links: branch diff | manifest | tags
Context
2026-10-25
13:49
The two regressions have been addressed in v16f. `lassign $it(*)` has returned to its previous perfo... check-in: 7a6b2e2ffd user: Florentis tags: tip-764_tcl90
13:02
I have updated `bench_cstruct.tcl` and re-run it on v16e: in compact mode, the full sequence runs 15... check-in: 23da210385 user: Florentis tags: tip-764_tcl90
12:58
Tuple assignment is now compiled into a single instruction: this is version 16e. It runs twice as fa... check-in: 28e84e2d0c user: Florentis tags: tip-764_tcl90
Changes