Skip to content
Tcl Source Code Changes To Faster UTF encoding
Login

Changes To Faster UTF encoding

Changes to "Faster UTF encoding" between 2026-02-25 07:58:38 and 2026-03-13 13:55:15

︙
15
16
17
18
19
20
21
22

23
24
25

26
27
28
29
30
31
32

33
34
35
36
37
38
39

40


41
















42
43


44
45
46
47
48
49
50
51
52







53
54
55

56


57
















58
59


60
61
62
63
64
65
66
67
68







69
70
71
72
73
74
75
15
16
17
18
19
20
21

22

23

24

25





26
27
28
29
30
31
32

33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53


54
55
56
57







58
59
60
61
62
63
64
65
66

67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87


88
89
90
91







92
93
94
95
96
97
98
99
100
101
102
103
104
105







-
+
-

-
+
-

-
-
-
-
-
+






-
+

+
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+


-
-
-
-
-
-
-
+
+
+
+
+
+
+


-
+

+
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+


-
-
-
-
-
-
-
+
+
+
+
+
+
+








The benchmark table shows timings when run against content based on the statistics above
as well as pathological worst case where ASCII characters alternate with non-ASCII characters.
As shown in the table,

* English (pure ASCII) timing is reduced by 75%
* West European timing is reduced by 50%
* Cyrillic is more or less unchanged
* Cyrillic and Far East both show measurable improvement though not as much as above
* Far East is reduced by 10%

On the flip side, for pathological cases timings are increased by 11-25% depending
On the flip side, for pathological cases (where characters alternate between the ASCII fastpath and normal processing) there is no marked difference.
on the language and operation.

**Given that the pathological cases are very unlikely to occur in practice and the
marked improvements for the likely statistical distribution of characters, it is
proposed that the changes be adopted.**

### Benchmarks
## Benchmarks

The I/O benchmarks reflect only the time for encoding, not Tcl command, channel overhead
etc.

(times in microseconds)

#### [apn-utf-fastpath](https://core.tcl-lang.org/tcl/timeline?r=apn-utf-fastpath) branch...
### [apn-utf-fastpath](https://core.tcl-lang.org/tcl/timeline?r=apn-utf-fastpath) branch...

**Linux (WSL gcc 11)**

```
apnadkarni@IO:/mnt/c/src/tcltk/wip/tcl/unix/build/22$ ./tcltest /mnt/c/src/tcltk/wip/tcl/win/utfbench.tcl 10000
Calibrating...0.035229554990273984 µs/#-overhead 0.035313 µs/# 55277069 # 28318170 #/sec

                                      convertto  convertfrom         puts         read
 ascii (10000)                            7.543        7.396        6.791        7.531
 western (10000)                         13.424       13.878       12.740       14.240
 cyrillic (10000)                        87.151       91.546       86.290       95.333
 eastern (10000)                        122.641      115.172      120.344      115.892
 western - pathological (10000)          67.377       71.195       66.244       74.391
 cyrillic - pathological (10000)         67.678       71.685       66.209       74.355
 eastern - pathological (10000)          72.026       73.623       70.780       77.394
```

**Windows VS2022**

```
c:\src\tcltk\wip\tcl\win>Release_AMD64_VC1944\tcltest91.exe utfbench.tcl 10000
Calibrating...0.03633541899879032 µs/#-overhead 0.037819 µs/# 51613951 # 26441573 #/sec
c:\src\tcltk\wip\tcl\win>Release_AMD64_VC1944\tcltest91.exe c:/src/tcltk/wip/tcl/win/utfbench.tcl 10000
Calibrating...0.035684211570548505 µs/#-overhead 0.037354 µs/# 52256094 # 26770539 #/sec

                                      convertto  convertfrom         puts         read
 ascii (10000)                            6.721        6.587        6.055        6.881
 western (10000)                         13.247       13.323       12.536       13.921
 cyrillic (10000)                        65.343       70.621       63.727       72.637
 eastern (10000)                         81.155       88.541       79.834       91.147
 western - pathological (10000)          60.158       61.249       59.822       62.990
 cyrillic - pathological (10000)         59.327       60.862       57.919       66.279
 eastern - pathological (10000)          64.834       67.425       63.501       69.091
 ascii (10000)                            7.033        6.836        6.358        7.191
 western (10000)                         12.524       12.762       11.840       12.910
 cyrillic (10000)                        65.135       65.291       63.650       65.360
 eastern (10000)                         82.112       81.329       81.534       88.101
 western - pathological (10000)          56.760       56.959       55.262       55.981
 cyrillic - pathological (10000)         56.568       56.792       55.627       56.974
 eastern - pathological (10000)          62.154       62.200       62.244       63.942
```

#### Current trunk
### Current trunk

**Linux (WSL gcc 11)**

```
apnadkarni@IO:/mnt/c/src/tcltk/main/tcl/unix/build/22$ ./tcltest /mnt/c/src/tcltk/wip/tcl/win/utfbench.tcl 10000
Calibrating...0.03797365585219985 µs/#-overhead 0.038160 µs/# 51154602 # 26205499 #/sec

                                      convertto  convertfrom         puts         read
 ascii (10000)                           23.296       23.203       22.695       23.248
 western (10000)                         27.787       27.604       26.921       28.032
 cyrillic (10000)                       114.211      114.608      111.627      115.822
 eastern (10000)                        135.507      134.657      134.713      139.039
 western - pathological (10000)          81.181       80.269       78.885       81.941
 cyrillic - pathological (10000)         80.334       80.369       80.079       82.513
 eastern - pathological (10000)          78.478       77.336       77.329       79.741
```

**Windows**

```
c:\src\tcltk\main\tcl\win>Release_AMD64_VC1944\tcltest91.exe ..\..\..\wip\tcl\win\utfbench.tcl 10000
Calibrating...0.0345694057395217 µs/#-overhead 0.035182 µs/# 55482315 # 28423317 #/sec
c:\src\tcltk\main\tcl\win>Release_AMD64_VC1944\tcltest91.exe c:/src/tcltk/wip/tcl/win/utfbench.tcl  10000
Calibrating...0.035101157673175384 µs/#-overhead 0.035233 µs/# 55402464 # 28382409 #/sec

                                      convertto  convertfrom         puts         read
 ascii (10000)                           22.834       22.802       22.279       23.333
 western (10000)                         25.434       25.694       24.925       26.320
 cyrillic (10000)                        65.016       70.840       64.997       72.914
 eastern (10000)                         92.401       96.693       92.304      101.501
 western - pathological (10000)          48.926       52.301       49.131       53.466
 cyrillic - pathological (10000)         48.742       52.250       49.659       53.592
 eastern - pathological (10000)          58.243       59.968       56.589       62.204
 ascii (10000)                           24.412       24.183       23.481       24.450
 western (10000)                         27.331       27.320       26.369       27.893
 cyrillic (10000)                        74.042       77.117       71.627       77.692
 eastern (10000)                         93.492      100.079       92.841      101.378
 western - pathological (10000)          54.441       55.761       53.439       59.602
 cyrillic - pathological (10000)         54.644       55.910       53.274       57.113
 eastern - pathological (10000)          60.719       64.458       59.521       63.114
```

The benchmark itself is below:

```
puts -nonewline "Calibrating..."
flush stdout
︙