Commit 4bdbe5f
perf(iconv): UTF-8 -> DBCS encode fast path — 2.6-3.7x, now beats glibc
UTF-8 -> DBCS legacy (Shift-JIS / Big5 / GBK / EUC-* / GB2312 / GB18030 / Johab)
encode still ran the generic UTF-8-source path: decode one char, then encode_one
+ encode_char (~100-arm dispatch) per char, plus outer-loop re-entry that
re-checks every preceding fast-path gate. Even with the O(1) direct-table
encoders (6750bb6), this measured 2.5-3.7x SLOWER than glibc (Shift-JIS 2.51x,
Big5 3.65x). The decode side (DBCS -> UTF-8) already had a tight loop; the encode
side did not.
Add a tight UTF-8 -> DBCS loop: decode each char inline (utf8_decode_step) then
call the per-codec encoder directly, skipping encode_char + encode_one and the
outer-loop re-entry. Byte-for-byte isomorphic: same decode + the same encode_*
the dispatch would pick; a decode error, unrepresentable char, or short room
breaks to the generic body for the exact EILSEQ/EINVAL/E2BIG ordering.
UTF-8->DBCS encode (ns/B, self / vs glibc):
SHIFT_JIS 3.73 -> 1.46 = 2.56x (2.51x -> 0.95x, now FASTER)
EUC-JP 5.41 -> 1.46 = 3.71x (0.60x -> 0.15x)
BIG5 3.77 -> 1.42 = 2.65x (3.65x -> 0.88x, now FASTER)
Isomorphism: iconv_differential_fuzz (7 tests; iconv_cjk_differential_fuzz_vs_glibc
covers UTF-8<->all 9 DBCS byte + errno + inbytesleft), 0 divergences vs host
glibc. Completes the iconv DBCS encode direction (decode side was done).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>1 parent 6fcb2f7 commit 4bdbe5f
1 file changed
Lines changed: 61 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9971 | 9971 | | |
9972 | 9972 | | |
9973 | 9973 | | |
| 9974 | + | |
| 9975 | + | |
| 9976 | + | |
| 9977 | + | |
| 9978 | + | |
| 9979 | + | |
| 9980 | + | |
| 9981 | + | |
| 9982 | + | |
| 9983 | + | |
| 9984 | + | |
| 9985 | + | |
| 9986 | + | |
| 9987 | + | |
| 9988 | + | |
| 9989 | + | |
| 9990 | + | |
| 9991 | + | |
| 9992 | + | |
| 9993 | + | |
| 9994 | + | |
| 9995 | + | |
| 9996 | + | |
| 9997 | + | |
| 9998 | + | |
| 9999 | + | |
| 10000 | + | |
| 10001 | + | |
| 10002 | + | |
| 10003 | + | |
| 10004 | + | |
| 10005 | + | |
| 10006 | + | |
| 10007 | + | |
| 10008 | + | |
| 10009 | + | |
| 10010 | + | |
| 10011 | + | |
| 10012 | + | |
| 10013 | + | |
| 10014 | + | |
| 10015 | + | |
| 10016 | + | |
| 10017 | + | |
| 10018 | + | |
| 10019 | + | |
| 10020 | + | |
| 10021 | + | |
| 10022 | + | |
| 10023 | + | |
| 10024 | + | |
| 10025 | + | |
| 10026 | + | |
| 10027 | + | |
| 10028 | + | |
| 10029 | + | |
| 10030 | + | |
| 10031 | + | |
| 10032 | + | |
| 10033 | + | |
| 10034 | + | |
9974 | 10035 | | |
9975 | 10036 | | |
9976 | 10037 | | |
| |||
0 commit comments