Commit Graph

21 Commits (71cc3a256845586f569a46cd0406bbf9c433ba35)

Author SHA1 Message Date
Nicholas Van Sickle 32e2ba754b
Add Dom::Path class for representing positions in a Dom (#7008)
* Add Dom::Path class for representing positions in a Dom

This also adds Value support for doing a path-based lookup.

The serialized representation is presently compliant with the JSON-pointer spec but the implementation supports Node types and may be later expanded if we require additional functionality (e.g. XPath style conditional querying).

Signed-off-by: Nicholas Van Sickle <nvsickle@amazon.com>
4 years ago
Nicholas Van Sickle cfd721bce1
A bit of Generic DOM tidying/fixup (#6914)
* A bit of Generic DOM tidying/fixup

- Refactor out a test fixture for all DOM tests / benchmarks
- Optimize `GetType` implementation to not use `AZStd::variant::visit` (benchmark included to A/B the implementations)
- Tag a few more mutating Value functions with "Mutable" to avoid astonishing copy-on-writes

Benchmark results for GetType implementation:
```
DomValueBenchmark/AzDomValueGetType_UsingVariantIndex              18.2 ns         18.0 ns     40727273 items_per_second=443.667M/s
DomValueBenchmark/AzDomValueGetType_UsingVariantVisit              32.2 ns         32.2 ns     21333333 items_per_second=248.242M/s
```

Signed-off-by: Nicholas Van Sickle <nvsickle@amazon.com>
4 years ago
Nicholas Van Sickle e7f573d22a Make Value ctor explicit
Signed-off-by: Nicholas Van Sickle <nvsickle@amazon.com>
4 years ago
Nicholas Van Sickle acc6248ec9 Move deep comparison / copy to utils
Signed-off-by: Nicholas Van Sickle <nvsickle@amazon.com>
4 years ago
Nicholas Van Sickle 41c0fb2b02 Address some review feedback
Signed-off-by: Nicholas Van Sickle <nvsickle@amazon.com>
4 years ago
Nicholas Van Sickle 37330c43a9 Address some more Generic Dom Value perf feedback
Signed-off-by: Nicholas Van Sickle <nvsickle@amazon.com>
4 years ago
Nicholas Van Sickle bbd00adade Address some AZ::Dom::Value feedback
- Use a vector for shared string storage (to avoid the double heap allocation for AZStd::string)
- Use a shared heap allocated any for opaque types (instead of an unsafe ref)
- Add a string comparison key lookup benchmark to measure the impact of Name

Signed-off-by: Nicholas Van Sickle <nvsickle@amazon.com>
4 years ago
Nicholas Van Sickle 8da04f15d3 Add some Value documentation
Signed-off-by: Nicholas Van Sickle <nvsickle@amazon.com>
4 years ago
Nicholas Van Sickle d9ac3c2120 Tidy up Type enum
Signed-off-by: Nicholas Van Sickle <nvsickle@amazon.com>
4 years ago
Nicholas Van Sickle cc120c772c Add RapidjsonCopyAndMutate to compare w/ shallow copy
Signed-off-by: Nicholas Van Sickle <nvsickle@amazon.com>
4 years ago
Nicholas Van Sickle c53c97cf5f Add another round of benchmarks
Signed-off-by: Nicholas Van Sickle <nvsickle@amazon.com>
4 years ago
Nicholas Van Sickle 1af39a5c5c Add benchmarks, some light optimizations like SSO
Signed-off-by: Nicholas Van Sickle <nvsickle@amazon.com>
4 years ago
Nicholas Van Sickle 947951b6c7 Add copy on write tests
Signed-off-by: Nicholas Van Sickle <nvsickle@amazon.com>
4 years ago
Nicholas Van Sickle 15e0bb1693 Add tests, fix missing bool in Accept and operator[] insert
Signed-off-by: Nicholas Van Sickle <nvsickle@amazon.com>
4 years ago
Nicholas Van Sickle a2d474cc4f Add some intial tests
Signed-off-by: Nicholas Van Sickle <nvsickle@amazon.com>
4 years ago
Nicholas Van Sickle 6cf805256b Make backend write API string-based
Signed-off-by: Nicholas Van Sickle <nvsickle@amazon.com>
4 years ago
Nicholas Van Sickle 8165f54c05 Use temporary lifetimes for test
Signed-off-by: Nicholas Van Sickle <nvsickle@amazon.com>
4 years ago
Nicholas Van Sickle 4dbce4275b Refactor the interface after some chatting with @amazon-employee-dm
Signed-off-by: Nicholas Van Sickle <nvsickle@amazon.com>
4 years ago
Nicholas Van Sickle a9c05372d5 API tweaks
- Use ref types
- Support using rapidjson::Value in lieu of rapidjson::Document
- Use the existing JSON comparison util function in tests

Signed-off-by: Nicholas Van Sickle <nvsickle@amazon.com>
4 years ago
Nicholas Van Sickle 5dbe9e387b Address some review feedback, remove DomBackendRegistry
Signed-off-by: Nicholas Van Sickle <nvsickle@amazon.com>
4 years ago
Nicholas Van Sickle e9a57380bb Generic DOM: Add DomBackend abstraction and JSON support
This change adds a `DomBackend` interface and a `DomBackendRegistry` for backend discovery (currently not hooked up to anything) alongside a JSON backend implementation.

The JSON backend comes with a small suite of unit and performance tests. The unit tests validate generic DOM conversion to and from serialized JSON and rapidjson::Document objects (the support for which lives in `JsonSerializationUtils.h`).

The performance tests show a throughput decrease compared to directly using the rapidjson serializer when mirroring our current pattern of copying strings from the serialized JSON representation, but with the coming in-memory store we have the opportunity to keep the buffer in memory and deserialize in-situ using rapidjson's API, which is consistently at least 100MiB/s faster on my machine (Ryzen Threadripper 3970X). The first parameter is the nested object complexity (N*N, objects with N keys comprised of arrays with N values) and the second parameter is the base size of the strings within each entry of this object.
```
----------------------------------------------------------------------------------------------------------------------
Benchmark                                                            Time             CPU   Iterations UserCounters...
----------------------------------------------------------------------------------------------------------------------
DomJsonBenchmark/DomDeserializeToDocumentInPlace/10/5            0.050 ms        0.050 ms        10000 bytes_per_second=355.816M/s
DomJsonBenchmark/DomDeserializeToDocumentInPlace/10/50           0.057 ms        0.057 ms        11200 bytes_per_second=386.064M/s
DomJsonBenchmark/DomDeserializeToDocumentInPlace/100/5            4.77 ms         4.88 ms          112 bytes_per_second=364.046M/s
DomJsonBenchmark/DomDeserializeToDocumentInPlace/100/500          11.6 ms         11.7 ms           64 bytes_per_second=554.518M/s
DomJsonBenchmark/DomDeserializeToDocumentWithCopies/10/5         0.084 ms        0.084 ms         7467 bytes_per_second=212.55M/s
DomJsonBenchmark/DomDeserializeToDocumentWithCopies/10/50        0.099 ms        0.100 ms         6400 bytes_per_second=220.608M/s
DomJsonBenchmark/DomDeserializeToDocumentWithCopies/100/5         8.22 ms         8.16 ms           90 bytes_per_second=217.847M/s
DomJsonBenchmark/DomDeserializeToDocumentWithCopies/100/500       23.2 ms         22.9 ms           30 bytes_per_second=283.56M/s
DomJsonBenchmark/JsonUtilsDeserializeToDocument/10/5             0.070 ms        0.070 ms        11200 bytes_per_second=255.049M/s
DomJsonBenchmark/JsonUtilsDeserializeToDocument/10/50            0.086 ms        0.087 ms         8960 bytes_per_second=253.258M/s
DomJsonBenchmark/JsonUtilsDeserializeToDocument/100/5             6.86 ms         6.84 ms          112 bytes_per_second=260.033M/s
DomJsonBenchmark/JsonUtilsDeserializeToDocument/100/500           22.8 ms         22.9 ms           32 bytes_per_second=283.158M/s
```

For `AZ::DOM::Document`, the current plan is to offer helper methods that can load from a file path or string using a given backend that can take advantage of in-place parsing by internally storing the serialized buffer.

Signed-off-by: Nicholas Van Sickle <nvsickle@amazon.com>
4 years ago