Repository navigation
zero-swift: JSON objects keep keys and key order as JS does - #14
Merged
Merged
Conversation
Amp-Thread-ID: https://ampcode.com/threads/T-c513a037-a257-45e0-b9a9-15c15edfe859 Co-authored-by: tmm <tmm@tmm.dev>
`JSONValue.object` holds a `JSONObject`: an ordered object whose keys compare by UTF-16 code unit, in JS property order (integer-like keys first, ascending, then insertion order). Canonically equivalent keys no longer merge in pokes, and JSON is written as `JSON.stringify` writes it. Amp-Thread-ID: https://ampcode.com/threads/T-c513a037-a257-45e0-b9a9-15c15edfe859 Co-authored-by: tmm <tmm@tmm.dev>
…weep generator macOS gives test threads a 512 KB stack, which a 4,000-deep value overflows. Amp-Thread-ID: https://ampcode.com/threads/T-c513a037-a257-45e0-b9a9-15c15edfe859 Co-authored-by: tmm <tmm@tmm.dev>
The main actor didn't help on macOS CI: the debug build still overflowed. Amp-Thread-ID: https://ampcode.com/threads/T-c513a037-a257-45e0-b9a9-15c15edfe859 Co-authored-by: tmm <tmm@tmm.dev>
A vector nests 1,000 deep, which overflows macOS's 512 KB test threads in a debug build. Amp-Thread-ID: https://ampcode.com/threads/T-c513a037-a257-45e0-b9a9-15c15edfe859 Co-authored-by: tmm <tmm@tmm.dev>
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.
Fixes a bug found by the bug sweep, with option (a) chosen by the user.
Bug:
JSONValue.objectwas a[String: JSONValue]. Swift strings compare by Unicode canonical equivalence, so keys like"\u00e9"and"e\u0301"merged and a value was lost. That dropped data from pokes (row values, primary keys, update merges, client IDs) and gave custom-query and AST hashes that differ from JS.Fix: a new public
JSONObjectvalue type (case object(JSONObject)):JSON.parsedoes;JSON.stringify; query hashes still sort keys, as JS does;subscript(key), ordered iteration,mapValues,mergeand.dictionarykeep it ergonomic.JSONValuestays 17 bytes.Breaking (minor changeset, with a migration note):
objectValue,ZeroObjectReader/Writer.objectandAST.Bound.rowareJSONObject;.object(dictVariable)needsJSONObject(dict). Mutator andstartAPIs still take dictionaries. zbugs needed a one-line change.Benchmarks (release, Linux): no regression; materialize 100k rows 7.61 → 6.20 ms, put 1000 changed rows 9.41 → 8.60 ms, memory for 100k rows 127.7 → 126.2 MB.
Checked: 173 Swift tests including all conformance vectors and 6 sweep wire tests generated from JS,
swift format lint --strict,ClientE2ETestsagainst a real zero-cache, and zbugs-swift builds its tests. TestHost can't build on Linux; macOS CI covers it.