Skip to content

bytes: document null termination - #4

Open
timbertson wants to merge 4 commits into
TimWhiting:dev-uvfrom
timbertson:dev-uv
Open

bytes: document null termination#4
timbertson wants to merge 4 commits into
TimWhiting:dev-uvfrom
timbertson:dev-uv

Conversation

@timbertson

Copy link
Copy Markdown
Collaborator

Pieced together from what I learnt in koka-community/uv#4 (comment)

TimWhiting added a commit that referenced this pull request Sep 8, 2026
A process-lifetime static has a stuck refcount (RC_STUCK == INT32_MIN), on
which dup and drop are semantically no-ops. But both are negative, so
kk_block_dup/kk_block_drop sent them down the `rc <= 0` path into the
out-of-line kk_block_check_dup/kk_block_check_drop -- every dup and every drop
of a static cost a real call to do nothing. Those two helpers were #2 and #4 by
self time (7.0% and 4.2%) in a profile of interface parsing.

Test the sticky range inline before the call. Ordinary blocks pay nothing:
with rc > 0 neither branch is taken, so the new test is only ever reached on
the already-slow path.

The hot static is the EMPTY EVIDENCE VECTOR: @open-none0/1/2 wraps every
effect operation in `evv-swap-create0(); ..; evv-set(w)`, dupping and dropping
that static twice per operation. The fix is general though -- every nullary
constructor and shared singleton pays the same toll.

Measured:
  C microbench, dup+drop of a static      3.4ns  -> 1.6ns
  C microbench, dup+drop of a normal block 2.5ns -> 2.5ns  (unchanged)
  tail-resumptive effect operation        13.7ns -> 10.2ns (-26%)
  parsing 209 interfaces                   56.2s -> 50.2s  (-10.7%)

425 examples 0 failures; koka-community port sweep 423/17/2/0 and multimodule
gate green.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.

2 participants