Repository navigation
Typed requests no longer link the JSON import - #6
Merged
Merged
Conversation
Codec held the JSON element bound to every model element (five tables of graphjson pointers) and the option-map scratch only JSON imports use, so a program that lays out only typed requests still linked the JSON import: the Codec type, pooled through an interface, named graphjson's types, and their MarshalJSON/UnmarshalJSON methods stayed reachable through encoding/json's interface calls. JSONCodec now owns all of that: it embeds *Codec, keeps the five tables and the option scratch, and has the JSON-only code moved verbatim from codec.go to jsoncodec.go (Import with its element importers and option import, TransferLayout with its store, the port/edge/label coordinate tables). Codec keeps the element steps shared with the typed import (bindNode, bindPort, addLabel, addEdge, ...), which no longer take the JSON element: JSONCodec records it right after each step succeeds. coordinatesOf is split into Codec.nodeCoordinates (all the typed read-back needs) and JSONCodec.coordinates (the rest). Layout(graph) acquires and releases a JSONCodec; its Codec still comes from and goes back to the codec pool, and the rest has a pool of its own with the same bound (2 MB in the slot, the sync.Pool under gc, dropped under TinyGo). PROVENANCE.md lists jsoncodec.go with the same ELK sources as codec.go. Outputs are unchanged by construction: every model operation, check and error happens in the same order; only where the JSON element pointers are kept moved, and typed imports no longer append nil entries to tables they never read. Tests that import JSON use NewJSONCodec/AcquireJSONCodec; TestReleasedCodecBounded also checks the JSON codec pool. go test ./... and -race (core, root, providers) pass; the d2 corpus test gives 356 of 356 responses identical. Co-Authored-By: Claude Opus 5.5 <[email protected]>
TryGet asserted the stored value's type in both of its lookup paths, and Has and Unset resolved a property's key in generic code, so every instantiation (one per property type) carried both copies. TryGet now finds the stored value first (by the precomputed key, or for a property without one by ID through the map's non-generic Raw) and asserts its type once; Has and Unset call HasKey/DeleteKey, or Has/Delete by ID, and the unused lookupKey goes. Same lookups in the same order: the key path still checks the mask before indexOf; the ID path is LookupPropertyKey then indexOf, as lookupKey and indexOf were; a failed assertion returns the zero value and false, as before. go test ./... and -race (graph, core, root) pass; the d2 corpus test gives 356 of 356 responses identical. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Programs that lay out only typed
Requests, as d2 does, no longer link elk-go's JSON import. Results are unchanged. d2's release binaries shrink by about 58 KB (darwin/amd64 -59,536 B, linux/amd64 -53,248 B, windows/amd64 -57,344 B), part of keeping them under their 45 MB budget.What changes (one commit each)
internal/core: the JSON import and the layout transfer move fromCodecto their own type,JSONCodec(jsoncodec.go). It embeds*Codecand owns the five tables of JSON elements and the option-map scratch. The element steps shared with the typed import (bindNode,bindPort,addLabel,addEdge, ...) stay inCodecand no longer take the JSON element;JSONCodecrecords it right after each step succeeds.Layout(graph)uses aJSONCodec: itsCodecstill comes from the codec pool, and the JSON part has a pool of its own with the same bound. The moved code is otherwise verbatim, and PROVENANCE.md listsjsoncodec.gowith the same ELK sources.internal/graph:TryGetasserts the stored value's type once instead of in both lookup paths, andHasandUnsetgo through the map's non-generic key functions, so each property type's instantiation is smaller.The public API is unchanged.
Checked
go test ./...andgo test -race ./...pass (32 packages), as do gofmt, vet and the js/wasm build. Every commit builds and vets on its own. Go 1.23 was not run locally; CI runs it.ci/test-wasm.sh, which runs the ELK adapter's tests) pass.d2 picks this up as v0.3.1 in d2lang/d2#2999.
🤖 Generated with Claude Code