Repository navigation
Conversation
A callback that only needs to know whether a value has changed since it last looked, such as a periodic pass over a whole group table, had to decode every value through the table's codec to see it. For a codec as costly as encoding/gob, that decode is most of the pass. The Context a callback is given, visit callbacks included, now also implements RawValuer. RawValue returns the key's value as the table stores it, encoded, or nil for an absent key, and fails the context on a storage error as Value does. The slice must be neither modified nor kept after the callback. It is an optional interface reached by type assertion, so Context and its other implementations are unchanged. Value reads through the same rawValueForKey, so the two cannot disagree about what is stored. TestContext_RawValue pins the bytes as stored (a codec.String table, which Value would decode), nil for an absent key, and a storage error failing the context. TestContext_RawValueStateless pins the stateless processor's refusal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
A callback that only needs to know whether a key's value has changed since it last looked has to decode the value through the table's codec to see it. A periodic
VisitAllpass over a large group table is the usual example. With a costly codec such asencoding/gob, that decode is most of the pass. Comparing the stored bytes, or a hash of them, would avoid it, butContextgives no way to read them.The change
The
Contexta callback is given, including a visit callback's, now also implements a new optional interface:RawValuereturns the key's value as the table stores it, still encoded, ornilif the key has none. A storage error fails the context, as it does forValue. The slice must be neither modified nor kept after the callback returns. The interface is reached by type assertion (ctx.(goka.RawValuer)), soContextand its other implementations, mocks included, do not change.Valuenow reads through the same internal lookup, so the two cannot disagree about what is stored.Tests
TestContext_RawValuechecks three things: acodec.Stringtable returns the stored bytes, whichValuewould decode; an absent key returnsnil; and a storage error fails the context.TestContext_RawValueStatelesschecks the refusal on a processor with no group table, the same refusalValuegives.go test -race ./...passes.