Skip to content

Commit c07dc5a

Browse files
committed
Reducing stack-size of hash-map allocated first-byte-mappings.
1 parent 27e0345 commit c07dc5a

File tree

8 files changed

+325
-333
lines changed

8 files changed

+325
-333
lines changed

Benchmarks/Tests.hpp

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ namespace tests {
9696
static constexpr bnch_swt::string_literal testNameRead{ testName + "-Read-Raw-Json-Data" };
9797
static constexpr bnch_swt::string_literal testNameWrite{ testName + "-Write-Raw-Json-Data" };
9898
static constexpr bool partialRead{ std::is_same_v<test_data_type, partial_test<partial_test_struct>> || std::is_same_v<test_data_type, twitter_partial_message> };
99-
static constexpr bool knownOrder{ !std::is_same_v<test_data_type, twitter_partial_message> && !std::is_same_v<test_data_type, abc_test<abc_test_struct>> };
99+
static constexpr bool knownOrder{ true };
100100
std::vector<std::string> newStrings{ iterations };
101101
results_data r{ jsonifierLibraryName, testName, jsonifierCommitUrl };
102102
jsonifier::jsonifier_core parser{};
@@ -166,7 +166,7 @@ namespace tests {
166166
static constexpr bnch_swt::string_literal testNameRead{ testName + "-Read" };
167167
static constexpr bnch_swt::string_literal testNameWrite{ testName + "-Write" };
168168
static constexpr bool partialRead{ std::is_same_v<test_data_type, partial_test<partial_test_struct>> || std::is_same_v<test_data_type, twitter_partial_message> };
169-
static constexpr bool knownOrder{ !std::is_same_v<test_data_type, twitter_partial_message> && !std::is_same_v<test_data_type, abc_test<abc_test_struct>> };
169+
static constexpr bool knownOrder{ true };
170170
results_data r{ jsonifierLibraryName, testName, jsonifierCommitUrl };
171171
jsonifier::jsonifier_core parser{};
172172
std::vector<std::vector<std::string>> newStrings{ iterations };
@@ -217,7 +217,7 @@ namespace tests {
217217
});
218218
r.readResult = result<result_type::read>{ "teal", readResult };
219219
r.writeResult = result<result_type::write>{ "steelblue", writeResult };
220-
bnch_swt::file_loader::saveFile(static_cast<std::string>(parser.serializeJson(testDatas[0])),
220+
bnch_swt::file_loader::saveFile(static_cast<std::string>(parser.serializeJson(testDatas)),
221221
jsonOutPath.operator std::string() + "/" + testName.operator std::string() + "-jsonifier.json");
222222
return r;
223223
}
@@ -230,7 +230,7 @@ namespace tests {
230230
static constexpr bnch_swt::string_literal testNameRead{ testName + "-Read" };
231231
static constexpr bnch_swt::string_literal testNameWrite{ testName + "-Write" };
232232
static constexpr bool partialRead{ std::is_same_v<test_data_type, partial_test<partial_test_struct>> || std::is_same_v<test_data_type, twitter_partial_message> };
233-
static constexpr bool knownOrder{ !std::is_same_v<test_data_type, twitter_partial_message> && !std::is_same_v<test_data_type, abc_test<abc_test_struct>> };
233+
static constexpr bool knownOrder{ true };
234234
results_data r{ jsonifierLibraryName, testName, jsonifierCommitUrl };
235235
jsonifier::jsonifier_core parser{};
236236
std::vector<std::string> newStrings{ iterations };
@@ -278,7 +278,7 @@ namespace tests {
278278
static constexpr bnch_swt::string_literal testNameRead{ testName + "-Read" };
279279
static constexpr bnch_swt::string_literal testNameWrite{ testName + "-Write" };
280280
static constexpr bool partialRead{ std::is_same_v<test_data_type, partial_test<partial_test_struct>> || std::is_same_v<test_data_type, twitter_partial_message> };
281-
static constexpr bool knownOrder{ !std::is_same_v<test_data_type, twitter_partial_message> && !std::is_same_v<test_data_type, abc_test<abc_test_struct>> };
281+
static constexpr bool knownOrder{ true };
282282
results_data r{ jsonifierLibraryName, testName, jsonifierCommitUrl };
283283
jsonifier::jsonifier_core parser{};
284284
std::vector<std::string> newStrings{ iterations };
@@ -422,7 +422,8 @@ namespace tests {
422422
testDatas[x].resize(testDataNew[x].size());
423423
}
424424
size_t currentIndex{};
425-
bnch_swt::performance_metrics readResult = bnch_swt::benchmark_stage<testNameRead, iterations, measuredIterations>::template runBenchmark<glazeLibraryName, "teal">([&]() mutable {
425+
bnch_swt::performance_metrics readResult =
426+
bnch_swt::benchmark_stage<testNameRead, iterations, measuredIterations>::template runBenchmark<glazeLibraryName, "teal">([&]() mutable {
426427
size_t newSize{};
427428
for (size_t x = 0; x < testDatas[currentIndex].size(); ++x) {
428429
get_ref_t<decltype(testDatas[currentIndex][x])> reference = testDatas[currentIndex][x];
@@ -439,7 +440,7 @@ namespace tests {
439440
}
440441
++currentIndex;
441442
return newSize;
442-
});
443+
});
443444
for (size_t x = 0; x < iterations; ++x) {
444445
for (size_t y = 0; y < testDataNew[x].size(); ++y) {
445446
newStrings[x][y] = std::string{};
@@ -462,7 +463,7 @@ namespace tests {
462463
r.readResult = result<result_type::read>{ "dodgerblue", readResult };
463464
r.writeResult = result<result_type::write>{ "skyblue", writeResult };
464465
std::string newString{};
465-
auto newResult = glz::write_json(testDatas[0], newString);
466+
auto newResult = glz::write_json(testDatas, newString);
466467
( void )newResult;
467468
bnch_swt::file_loader::saveFile(newString, jsonOutPath.operator std::string() + "/" + testName.operator std::string() + "-glaze.json");
468469
return r;
@@ -669,7 +670,7 @@ namespace tests {
669670
});
670671
r.readResult = result<result_type::read>{ "cadetblue", readResult };
671672
std::string newString{};
672-
auto newResult = glz::write_json(testDatas[0], newString);
673+
auto newResult = glz::write_json(testDatas, newString);
673674
( void )newResult;
674675
bnch_swt::file_loader::saveFile(newString, jsonOutPath.operator std::string() + "/" + testName.operator std::string() + "-simdjson.json");
675676
return r;
@@ -994,21 +995,13 @@ In contrast, hash-based solutions offer a viable alternative by circumventing th
994995
JSONIFIER_CLANG_INLINE void testFunction() {
995996
std::string jsonDataNew{};
996997
jsonifier::jsonifier_core parser{};
997-
std::vector<test_struct> jsonDataSmallNewer{ maxIterations };
998-
for (size_t x = 0; x < maxIterations; ++x) {
999-
jsonDataSmallNewer[x] = test_generator::generateTestStruct();
1000-
}
1001998
std::vector<test<test_struct>> jsonDataNewer{ maxIterations };
1002999
for (size_t x = 0; x < maxIterations; ++x) {
10031000
jsonDataNewer[x] = test_generator::generateTest();
10041001
}
1005-
parser.serializeJson<jsonifier::serialize_options{ .prettify = true }>(jsonDataSmallNewer[0], jsonDataNew);
1006-
bnch_swt::file_loader::saveFile(jsonDataNew, jsonOutPath.operator std::string() + "/Json Test (Small) (Prettified).json");
1007-
std::string jsonMinifiedData{ parser.minifyJson(jsonDataNew) };
1008-
bnch_swt::file_loader::saveFile(jsonMinifiedData, jsonOutPath.operator std::string() + "/Json Test (Small) (Minified).json");
10091002
parser.serializeJson<jsonifier::serialize_options{ .prettify = true }>(jsonDataNewer[0], jsonDataNew);
10101003
bnch_swt::file_loader::saveFile(jsonDataNew, jsonOutPath.operator std::string() + "/Json Test (Prettified).json");
1011-
jsonMinifiedData = parser.minifyJson(jsonDataNew);
1004+
std::string jsonMinifiedData = parser.minifyJson(jsonDataNew);
10121005
bnch_swt::file_loader::saveFile(jsonMinifiedData, jsonOutPath.operator std::string() + "/Json Test (Minified).json");
10131006
bnch_swt::file_loader::saveFile(jsonDataNew, jsonOutPath.operator std::string() + "/Partial Test (Prettified).json");
10141007
bnch_swt::file_loader::saveFile(jsonMinifiedData, jsonOutPath.operator std::string() + "/Partial Test (Minified).json");
@@ -1023,51 +1016,45 @@ In contrast, hash-based solutions offer a viable alternative by circumventing th
10231016
static_cast<std::string>(section001) };
10241017
test_results testResults{};
10251018
{
1026-
std::vector<std::vector<double>> doubleData{ test_generator::generateValues<double>(maxIterations, 2500) };
1027-
parser.serializeJson<jsonifier::serialize_options{ .prettify = true }>(doubleData[0], jsonDataNew);
1019+
std::vector<std::vector<double>> doubleData{ test_generator::generateValues<double>(maxIterations, 100) };
1020+
parser.serializeJson<jsonifier::serialize_options{ .prettify = true }>(doubleData, jsonDataNew);
10281021
bnch_swt::file_loader::saveFile(jsonDataNew, jsonOutPath.operator std::string() + "/Double Test.json");
10291022
testResults = json_tests_helper<test_type::parse_and_serialize, std::vector<std::vector<double>>, false, maxIterations, "Double Test">::run(doubleData);
10301023
newerString += testResults.markdownResults;
10311024
benchmark_data.emplace_back(testResults);
10321025
}
10331026
{
1034-
std::vector<std::vector<std::string>> stringData{ test_generator::generateValues<std::string>(maxIterations, 2500) };
1035-
parser.serializeJson<jsonifier::serialize_options{ .prettify = true }>(stringData[0], jsonDataNew);
1027+
std::vector<std::vector<std::string>> stringData{ test_generator::generateValues<std::string>(maxIterations, 100) };
1028+
parser.serializeJson<jsonifier::serialize_options{ .prettify = true }>(stringData, jsonDataNew);
10361029
bnch_swt::file_loader::saveFile(jsonDataNew, jsonOutPath.operator std::string() + "/String Test.json");
10371030
testResults = json_tests_helper<test_type::parse_and_serialize, std::vector<std::vector<std::string>>, false, maxIterations, "String Test">::run(stringData);
10381031
newerString += testResults.markdownResults;
10391032
benchmark_data.emplace_back(testResults);
10401033
}
10411034
{
1042-
std::vector<std::vector<uint64_t>> uintData{ test_generator::generateValues<uint64_t>(maxIterations, 2500) };
1043-
parser.serializeJson<jsonifier::serialize_options{ .prettify = true }>(uintData[0], jsonDataNew);
1035+
std::vector<std::vector<uint64_t>> uintData{ test_generator::generateValues<uint64_t>(maxIterations, 100) };
1036+
parser.serializeJson<jsonifier::serialize_options{ .prettify = true }>(uintData, jsonDataNew);
10441037
bnch_swt::file_loader::saveFile(jsonDataNew, jsonOutPath.operator std::string() + "/Uint Test.json");
10451038
testResults = json_tests_helper<test_type::parse_and_serialize, std::vector<std::vector<uint64_t>>, false, maxIterations, "Uint Test">::run(uintData);
10461039
newerString += testResults.markdownResults;
10471040
benchmark_data.emplace_back(testResults);
10481041
}
10491042
{
1050-
std::vector<std::vector<int64_t>> intData{ test_generator::generateValues<int64_t>(maxIterations, 2500) };
1051-
parser.serializeJson<jsonifier::serialize_options{ .prettify = true }>(intData[0], jsonDataNew);
1043+
std::vector<std::vector<int64_t>> intData{ test_generator::generateValues<int64_t>(maxIterations, 100) };
1044+
parser.serializeJson<jsonifier::serialize_options{ .prettify = true }>(intData, jsonDataNew);
10521045
bnch_swt::file_loader::saveFile(jsonDataNew, jsonOutPath.operator std::string() + "/Int Test.json");
10531046
testResults = json_tests_helper<test_type::parse_and_serialize, std::vector<std::vector<int64_t>>, false, maxIterations, "Int Test">::run(intData);
10541047
newerString += testResults.markdownResults;
10551048
benchmark_data.emplace_back(testResults);
10561049
}
10571050
{
1058-
std::vector<std::vector<bool>> boolData{ test_generator::generateValues<bool>(maxIterations, 2500) };
1059-
parser.serializeJson<jsonifier::serialize_options{ .prettify = true }>(boolData[0], jsonDataNew);
1051+
std::vector<std::vector<bool>> boolData{ test_generator::generateValues<bool>(maxIterations, 100) };
1052+
parser.serializeJson<jsonifier::serialize_options{ .prettify = true }>(boolData, jsonDataNew);
10601053
bnch_swt::file_loader::saveFile(jsonDataNew, jsonOutPath.operator std::string() + "/Bool Test.json");
10611054
testResults = json_tests_helper<test_type::parse_and_serialize, std::vector<std::vector<bool>>, false, maxIterations, "Bool Test">::run(boolData);
10621055
newerString += testResults.markdownResults;
10631056
benchmark_data.emplace_back(testResults);
10641057
}
1065-
testResults = json_tests_helper<test_type::parse_and_serialize, test_struct, false, maxIterations, "Json Test (Small) (Prettified)">::run(jsonDataSmallNewer);
1066-
newerString += testResults.markdownResults;
1067-
benchmark_data.emplace_back(testResults);
1068-
testResults = json_tests_helper<test_type::parse_and_serialize, test_struct, true, maxIterations, "Json Test (Small) (Minified)">::run(jsonDataSmallNewer);
1069-
newerString += testResults.markdownResults;
1070-
benchmark_data.emplace_back(testResults);
10711058
testResults = json_tests_helper<test_type::parse_and_serialize, test<test_struct>, false, maxIterations, "Json Test (Prettified)">::run(jsonDataNewer);
10721059
newerString += testResults.markdownResults;
10731060
benchmark_data.emplace_back(testResults);

Include/jsonifier/Containers/Array.hpp

Lines changed: 1 addition & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -26,147 +26,7 @@
2626
#include <jsonifier/Core/Config.hpp>
2727
#include <jsonifier/Containers/Iterator.hpp>
2828

29-
namespace jsonifier::internal {
30-
31-
template<typename value_type_new, size_t size> class array_iterator {
32-
public:
33-
using iterator_concept = std::contiguous_iterator_tag;
34-
using iterator_category = std::random_access_iterator_tag;
35-
using element_type = value_type_new;
36-
using value_type = value_type_new;
37-
using difference_type = std::ptrdiff_t;
38-
using pointer = value_type*;
39-
using reference = value_type&;
40-
41-
JSONIFIER_INLINE constexpr array_iterator() noexcept : ptr() {
42-
}
43-
44-
JSONIFIER_INLINE constexpr array_iterator(pointer ptrNew) noexcept : ptr(ptrNew) {
45-
}
46-
47-
JSONIFIER_INLINE constexpr reference operator*() const noexcept {
48-
return *ptr;
49-
}
50-
51-
JSONIFIER_INLINE constexpr pointer operator->() const noexcept {
52-
return std::pointer_traits<pointer>::pointer_to(**this);
53-
}
54-
55-
JSONIFIER_INLINE constexpr array_iterator& operator++() noexcept {
56-
++ptr;
57-
return *this;
58-
}
59-
60-
JSONIFIER_INLINE constexpr array_iterator operator++(int32_t) noexcept {
61-
array_iterator temp = *this;
62-
++*this;
63-
return temp;
64-
}
65-
66-
JSONIFIER_INLINE constexpr array_iterator& operator--() noexcept {
67-
--ptr;
68-
return *this;
69-
}
70-
71-
JSONIFIER_INLINE constexpr array_iterator operator--(int32_t) noexcept {
72-
array_iterator temp = *this;
73-
--*this;
74-
return temp;
75-
}
76-
77-
JSONIFIER_INLINE constexpr array_iterator& operator+=(const difference_type offSet) noexcept {
78-
ptr += offSet;
79-
return *this;
80-
}
81-
82-
JSONIFIER_INLINE constexpr array_iterator operator+(const difference_type offSet) const noexcept {
83-
array_iterator temp = *this;
84-
temp += offSet;
85-
return temp;
86-
}
87-
88-
JSONIFIER_INLINE friend constexpr array_iterator operator+(const difference_type offSet, array_iterator _Next) noexcept {
89-
_Next += offSet;
90-
return _Next;
91-
}
92-
93-
JSONIFIER_INLINE constexpr array_iterator& operator-=(const difference_type offSet) noexcept {
94-
return *this += -offSet;
95-
}
96-
97-
JSONIFIER_INLINE constexpr array_iterator operator-(const difference_type offSet) const noexcept {
98-
array_iterator temp = *this;
99-
temp -= offSet;
100-
return temp;
101-
}
102-
103-
JSONIFIER_INLINE constexpr difference_type operator-(const array_iterator& other) const noexcept {
104-
return static_cast<difference_type>(ptr - other.ptr);
105-
}
106-
107-
JSONIFIER_INLINE constexpr reference operator[](const difference_type offSet) const noexcept {
108-
return *(*this + offSet);
109-
}
110-
111-
JSONIFIER_INLINE constexpr bool operator==(const array_iterator& other) const noexcept {
112-
return ptr == other.ptr;
113-
}
114-
115-
JSONIFIER_INLINE constexpr std::strong_ordering operator<=>(const array_iterator& other) const noexcept {
116-
return ptr <=> other.ptr;
117-
}
118-
119-
JSONIFIER_INLINE constexpr bool operator!=(const array_iterator& other) const noexcept {
120-
return !(*this == other);
121-
}
122-
123-
JSONIFIER_INLINE constexpr bool operator<(const array_iterator& other) const noexcept {
124-
return ptr < other.ptr;
125-
}
126-
127-
JSONIFIER_INLINE constexpr bool operator>(const array_iterator& other) const noexcept {
128-
return other < *this;
129-
}
130-
131-
JSONIFIER_INLINE constexpr bool operator<=(const array_iterator& other) const noexcept {
132-
return !(other < *this);
133-
}
134-
135-
JSONIFIER_INLINE constexpr bool operator>=(const array_iterator& other) const noexcept {
136-
return !(*this < other);
137-
}
138-
139-
pointer ptr;
140-
};
141-
142-
template<typename value_type_new> class array_iterator<value_type_new, 0> {
143-
public:
144-
using iterator_concept = std::contiguous_iterator_tag;
145-
using iterator_category = std::random_access_iterator_tag;
146-
using element_type = value_type_new;
147-
using value_type = value_type_new;
148-
using difference_type = std::ptrdiff_t;
149-
using pointer = value_type*;
150-
using reference = value_type&;
151-
152-
JSONIFIER_INLINE constexpr array_iterator() noexcept {
153-
}
154-
155-
JSONIFIER_INLINE constexpr array_iterator(std::nullptr_t ptrNew) noexcept {
156-
}
157-
158-
JSONIFIER_INLINE constexpr bool operator==(const array_iterator& other) const noexcept {
159-
return true;
160-
}
161-
162-
JSONIFIER_INLINE constexpr bool operator!=(const array_iterator& other) const noexcept {
163-
return !(*this == other);
164-
}
165-
166-
JSONIFIER_INLINE constexpr bool operator>=(const array_iterator& other) const noexcept {
167-
return !(*this < other);
168-
}
169-
};
29+
namespace jsonifier::internal {
17030

17131
template<typename value_type_new, size_t sizeNew> struct array {
17232
using value_type = value_type_new;

0 commit comments

Comments
 (0)