Skip to content

perf: choose the codec when the decoder is built - #37

Merged
Taure merged 1 commit into
mainfrom
perf/collapse-codec-dispatch
Aug 6, 2026
Merged

perf: choose the codec when the decoder is built#37
Taure merged 1 commit into
mainfrom
perf/collapse-codec-dispatch

Conversation

@Taure

@Taure Taure commented Aug 6, 2026

Copy link
Copy Markdown
Owner

Third of the items the profile turned up: minato_codec:decode/2 and decode_named/4 were each called once per column, 16% of the profile combined, for what is one logical operation.

decode/2 matched a scalar decoder and then called decode_named/4, which tested for numeric, then for the four datetime names, before falling through to the scalar codec. Those names are fixed by the RowDescription, so the walk was answering the same question once per value.

The decoder now carries which codec to call. decode/2 is one clause and one static call. decode_named/4 stays, because decode/4 has no decoder to carry the answer.

reductions / 5000-row query
before 112,898
after 103,685 (-8%)

Cumulative over #33, #34, #35 and this: 172,841 to 103,685, 40% less work per query.

The opaque decoder() gained tighter types on the way: {numeric, format(), opts()} and {datetime, date | time | timestamp | timestamptz, format(), opts()}. eqwalizer rejected the first attempt, which passed the whole name union to codecs that accept one name or four - correlating the tag with the name in resolved/3 fixed it, and the types now say what each codec actually takes.

Checklist green: fmt, xref, dialyzer, eqwalize-all, elp lint, ex_doc, 1398 eunit, 137 ct.

decode/2 matched a scalar decoder and then called decode_named/4, which
walked the names that need a codec of their own before falling through to the
scalar one. The name is fixed by the RowDescription, so that walk answered the
same question once per value.

The decoder now carries which codec to call, so decode/2 is one clause and one
call. decode_named/4 stays for decode/4, which has no decoder to carry it.

112,898 to 103,685 reductions per five thousand row query.
@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown

🟢 Code Coverage — 90.2%

1624 of 1801 lines covered.


✅ ELP Lint

No diagnostics.

@Taure
Taure merged commit be624c9 into main Aug 6, 2026
18 checks passed
@Taure
Taure deleted the perf/collapse-codec-dispatch branch August 6, 2026 12:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant