Skip to content

Commit

Permalink
Reducing stack-size of hash-map allocated first-byte-mappings.
Browse files Browse the repository at this point in the history
  • Loading branch information
RealTimeChris committed Feb 3, 2025
1 parent 27e0345 commit bdea5d6
Show file tree
Hide file tree
Showing 8 changed files with 321 additions and 333 deletions.
55 changes: 21 additions & 34 deletions Benchmarks/Tests.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ namespace tests {
static constexpr bnch_swt::string_literal testNameRead{ testName + "-Read-Raw-Json-Data" };
static constexpr bnch_swt::string_literal testNameWrite{ testName + "-Write-Raw-Json-Data" };
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> };
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>> };
static constexpr bool knownOrder{ true };
std::vector<std::string> newStrings{ iterations };
results_data r{ jsonifierLibraryName, testName, jsonifierCommitUrl };
jsonifier::jsonifier_core parser{};
Expand Down Expand Up @@ -166,7 +166,7 @@ namespace tests {
static constexpr bnch_swt::string_literal testNameRead{ testName + "-Read" };
static constexpr bnch_swt::string_literal testNameWrite{ testName + "-Write" };
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> };
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>> };
static constexpr bool knownOrder{ true };
results_data r{ jsonifierLibraryName, testName, jsonifierCommitUrl };
jsonifier::jsonifier_core parser{};
std::vector<std::vector<std::string>> newStrings{ iterations };
Expand Down Expand Up @@ -217,7 +217,7 @@ namespace tests {
});
r.readResult = result<result_type::read>{ "teal", readResult };
r.writeResult = result<result_type::write>{ "steelblue", writeResult };
bnch_swt::file_loader::saveFile(static_cast<std::string>(parser.serializeJson(testDatas[0])),
bnch_swt::file_loader::saveFile(static_cast<std::string>(parser.serializeJson(testDatas)),
jsonOutPath.operator std::string() + "/" + testName.operator std::string() + "-jsonifier.json");
return r;
}
Expand All @@ -230,7 +230,7 @@ namespace tests {
static constexpr bnch_swt::string_literal testNameRead{ testName + "-Read" };
static constexpr bnch_swt::string_literal testNameWrite{ testName + "-Write" };
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> };
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>> };
static constexpr bool knownOrder{ true };
results_data r{ jsonifierLibraryName, testName, jsonifierCommitUrl };
jsonifier::jsonifier_core parser{};
std::vector<std::string> newStrings{ iterations };
Expand Down Expand Up @@ -278,7 +278,7 @@ namespace tests {
static constexpr bnch_swt::string_literal testNameRead{ testName + "-Read" };
static constexpr bnch_swt::string_literal testNameWrite{ testName + "-Write" };
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> };
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>> };
static constexpr bool knownOrder{ true };
results_data r{ jsonifierLibraryName, testName, jsonifierCommitUrl };
jsonifier::jsonifier_core parser{};
std::vector<std::string> newStrings{ iterations };
Expand Down Expand Up @@ -422,7 +422,8 @@ namespace tests {
testDatas[x].resize(testDataNew[x].size());
}
size_t currentIndex{};
bnch_swt::performance_metrics readResult = bnch_swt::benchmark_stage<testNameRead, iterations, measuredIterations>::template runBenchmark<glazeLibraryName, "teal">([&]() mutable {
bnch_swt::performance_metrics readResult =
bnch_swt::benchmark_stage<testNameRead, iterations, measuredIterations>::template runBenchmark<glazeLibraryName, "teal">([&]() mutable {
size_t newSize{};
for (size_t x = 0; x < testDatas[currentIndex].size(); ++x) {
get_ref_t<decltype(testDatas[currentIndex][x])> reference = testDatas[currentIndex][x];
Expand All @@ -439,7 +440,7 @@ namespace tests {
}
++currentIndex;
return newSize;
});
});
for (size_t x = 0; x < iterations; ++x) {
for (size_t y = 0; y < testDataNew[x].size(); ++y) {
newStrings[x][y] = std::string{};
Expand All @@ -462,7 +463,7 @@ namespace tests {
r.readResult = result<result_type::read>{ "dodgerblue", readResult };
r.writeResult = result<result_type::write>{ "skyblue", writeResult };
std::string newString{};
auto newResult = glz::write_json(testDatas[0], newString);
auto newResult = glz::write_json(testDatas, newString);
( void )newResult;
bnch_swt::file_loader::saveFile(newString, jsonOutPath.operator std::string() + "/" + testName.operator std::string() + "-glaze.json");
return r;
Expand Down Expand Up @@ -669,7 +670,7 @@ namespace tests {
});
r.readResult = result<result_type::read>{ "cadetblue", readResult };
std::string newString{};
auto newResult = glz::write_json(testDatas[0], newString);
auto newResult = glz::write_json(testDatas, newString);
( void )newResult;
bnch_swt::file_loader::saveFile(newString, jsonOutPath.operator std::string() + "/" + testName.operator std::string() + "-simdjson.json");
return r;
Expand Down Expand Up @@ -994,21 +995,13 @@ In contrast, hash-based solutions offer a viable alternative by circumventing th
JSONIFIER_CLANG_INLINE void testFunction() {
std::string jsonDataNew{};
jsonifier::jsonifier_core parser{};
std::vector<test_struct> jsonDataSmallNewer{ maxIterations };
for (size_t x = 0; x < maxIterations; ++x) {
jsonDataSmallNewer[x] = test_generator::generateTestStruct();
}
std::vector<test<test_struct>> jsonDataNewer{ maxIterations };
for (size_t x = 0; x < maxIterations; ++x) {
jsonDataNewer[x] = test_generator::generateTest();
}
parser.serializeJson<jsonifier::serialize_options{ .prettify = true }>(jsonDataSmallNewer[0], jsonDataNew);
bnch_swt::file_loader::saveFile(jsonDataNew, jsonOutPath.operator std::string() + "/Json Test (Small) (Prettified).json");
std::string jsonMinifiedData{ parser.minifyJson(jsonDataNew) };
bnch_swt::file_loader::saveFile(jsonMinifiedData, jsonOutPath.operator std::string() + "/Json Test (Small) (Minified).json");
parser.serializeJson<jsonifier::serialize_options{ .prettify = true }>(jsonDataNewer[0], jsonDataNew);
bnch_swt::file_loader::saveFile(jsonDataNew, jsonOutPath.operator std::string() + "/Json Test (Prettified).json");
jsonMinifiedData = parser.minifyJson(jsonDataNew);
std::string jsonMinifiedData = parser.minifyJson(jsonDataNew);
bnch_swt::file_loader::saveFile(jsonMinifiedData, jsonOutPath.operator std::string() + "/Json Test (Minified).json");
bnch_swt::file_loader::saveFile(jsonDataNew, jsonOutPath.operator std::string() + "/Partial Test (Prettified).json");
bnch_swt::file_loader::saveFile(jsonMinifiedData, jsonOutPath.operator std::string() + "/Partial Test (Minified).json");
Expand All @@ -1023,51 +1016,45 @@ In contrast, hash-based solutions offer a viable alternative by circumventing th
static_cast<std::string>(section001) };
test_results testResults{};
{
std::vector<std::vector<double>> doubleData{ test_generator::generateValues<double>(maxIterations, 2500) };
parser.serializeJson<jsonifier::serialize_options{ .prettify = true }>(doubleData[0], jsonDataNew);
std::vector<std::vector<double>> doubleData{ test_generator::generateValues<double>(maxIterations, 100) };
parser.serializeJson<jsonifier::serialize_options{ .prettify = true }>(doubleData, jsonDataNew);
bnch_swt::file_loader::saveFile(jsonDataNew, jsonOutPath.operator std::string() + "/Double Test.json");
testResults = json_tests_helper<test_type::parse_and_serialize, std::vector<std::vector<double>>, false, maxIterations, "Double Test">::run(doubleData);
newerString += testResults.markdownResults;
benchmark_data.emplace_back(testResults);
}
{
std::vector<std::vector<std::string>> stringData{ test_generator::generateValues<std::string>(maxIterations, 2500) };
parser.serializeJson<jsonifier::serialize_options{ .prettify = true }>(stringData[0], jsonDataNew);
std::vector<std::vector<std::string>> stringData{ test_generator::generateValues<std::string>(maxIterations, 100) };
parser.serializeJson<jsonifier::serialize_options{ .prettify = true }>(stringData, jsonDataNew);
bnch_swt::file_loader::saveFile(jsonDataNew, jsonOutPath.operator std::string() + "/String Test.json");
testResults = json_tests_helper<test_type::parse_and_serialize, std::vector<std::vector<std::string>>, false, maxIterations, "String Test">::run(stringData);
newerString += testResults.markdownResults;
benchmark_data.emplace_back(testResults);
}
{
std::vector<std::vector<uint64_t>> uintData{ test_generator::generateValues<uint64_t>(maxIterations, 2500) };
parser.serializeJson<jsonifier::serialize_options{ .prettify = true }>(uintData[0], jsonDataNew);
std::vector<std::vector<uint64_t>> uintData{ test_generator::generateValues<uint64_t>(maxIterations, 100) };
parser.serializeJson<jsonifier::serialize_options{ .prettify = true }>(uintData, jsonDataNew);
bnch_swt::file_loader::saveFile(jsonDataNew, jsonOutPath.operator std::string() + "/Uint Test.json");
testResults = json_tests_helper<test_type::parse_and_serialize, std::vector<std::vector<uint64_t>>, false, maxIterations, "Uint Test">::run(uintData);
newerString += testResults.markdownResults;
benchmark_data.emplace_back(testResults);
}
{
std::vector<std::vector<int64_t>> intData{ test_generator::generateValues<int64_t>(maxIterations, 2500) };
parser.serializeJson<jsonifier::serialize_options{ .prettify = true }>(intData[0], jsonDataNew);
std::vector<std::vector<int64_t>> intData{ test_generator::generateValues<int64_t>(maxIterations, 100) };
parser.serializeJson<jsonifier::serialize_options{ .prettify = true }>(intData, jsonDataNew);
bnch_swt::file_loader::saveFile(jsonDataNew, jsonOutPath.operator std::string() + "/Int Test.json");
testResults = json_tests_helper<test_type::parse_and_serialize, std::vector<std::vector<int64_t>>, false, maxIterations, "Int Test">::run(intData);
newerString += testResults.markdownResults;
benchmark_data.emplace_back(testResults);
}
{
std::vector<std::vector<bool>> boolData{ test_generator::generateValues<bool>(maxIterations, 2500) };
parser.serializeJson<jsonifier::serialize_options{ .prettify = true }>(boolData[0], jsonDataNew);
std::vector<std::vector<bool>> boolData{ test_generator::generateValues<bool>(maxIterations, 100) };
parser.serializeJson<jsonifier::serialize_options{ .prettify = true }>(boolData, jsonDataNew);
bnch_swt::file_loader::saveFile(jsonDataNew, jsonOutPath.operator std::string() + "/Bool Test.json");
testResults = json_tests_helper<test_type::parse_and_serialize, std::vector<std::vector<bool>>, false, maxIterations, "Bool Test">::run(boolData);
newerString += testResults.markdownResults;
benchmark_data.emplace_back(testResults);
}
testResults = json_tests_helper<test_type::parse_and_serialize, test_struct, false, maxIterations, "Json Test (Small) (Prettified)">::run(jsonDataSmallNewer);
newerString += testResults.markdownResults;
benchmark_data.emplace_back(testResults);
testResults = json_tests_helper<test_type::parse_and_serialize, test_struct, true, maxIterations, "Json Test (Small) (Minified)">::run(jsonDataSmallNewer);
newerString += testResults.markdownResults;
benchmark_data.emplace_back(testResults);
testResults = json_tests_helper<test_type::parse_and_serialize, test<test_struct>, false, maxIterations, "Json Test (Prettified)">::run(jsonDataNewer);
newerString += testResults.markdownResults;
benchmark_data.emplace_back(testResults);
Expand Down
142 changes: 1 addition & 141 deletions Include/jsonifier/Containers/Array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,147 +26,7 @@
#include <jsonifier/Core/Config.hpp>
#include <jsonifier/Containers/Iterator.hpp>

namespace jsonifier::internal {

template<typename value_type_new, size_t size> class array_iterator {
public:
using iterator_concept = std::contiguous_iterator_tag;
using iterator_category = std::random_access_iterator_tag;
using element_type = value_type_new;
using value_type = value_type_new;
using difference_type = std::ptrdiff_t;
using pointer = value_type*;
using reference = value_type&;

JSONIFIER_INLINE constexpr array_iterator() noexcept : ptr() {
}

JSONIFIER_INLINE constexpr array_iterator(pointer ptrNew) noexcept : ptr(ptrNew) {
}

JSONIFIER_INLINE constexpr reference operator*() const noexcept {
return *ptr;
}

JSONIFIER_INLINE constexpr pointer operator->() const noexcept {
return std::pointer_traits<pointer>::pointer_to(**this);
}

JSONIFIER_INLINE constexpr array_iterator& operator++() noexcept {
++ptr;
return *this;
}

JSONIFIER_INLINE constexpr array_iterator operator++(int32_t) noexcept {
array_iterator temp = *this;
++*this;
return temp;
}

JSONIFIER_INLINE constexpr array_iterator& operator--() noexcept {
--ptr;
return *this;
}

JSONIFIER_INLINE constexpr array_iterator operator--(int32_t) noexcept {
array_iterator temp = *this;
--*this;
return temp;
}

JSONIFIER_INLINE constexpr array_iterator& operator+=(const difference_type offSet) noexcept {
ptr += offSet;
return *this;
}

JSONIFIER_INLINE constexpr array_iterator operator+(const difference_type offSet) const noexcept {
array_iterator temp = *this;
temp += offSet;
return temp;
}

JSONIFIER_INLINE friend constexpr array_iterator operator+(const difference_type offSet, array_iterator _Next) noexcept {
_Next += offSet;
return _Next;
}

JSONIFIER_INLINE constexpr array_iterator& operator-=(const difference_type offSet) noexcept {
return *this += -offSet;
}

JSONIFIER_INLINE constexpr array_iterator operator-(const difference_type offSet) const noexcept {
array_iterator temp = *this;
temp -= offSet;
return temp;
}

JSONIFIER_INLINE constexpr difference_type operator-(const array_iterator& other) const noexcept {
return static_cast<difference_type>(ptr - other.ptr);
}

JSONIFIER_INLINE constexpr reference operator[](const difference_type offSet) const noexcept {
return *(*this + offSet);
}

JSONIFIER_INLINE constexpr bool operator==(const array_iterator& other) const noexcept {
return ptr == other.ptr;
}

JSONIFIER_INLINE constexpr std::strong_ordering operator<=>(const array_iterator& other) const noexcept {
return ptr <=> other.ptr;
}

JSONIFIER_INLINE constexpr bool operator!=(const array_iterator& other) const noexcept {
return !(*this == other);
}

JSONIFIER_INLINE constexpr bool operator<(const array_iterator& other) const noexcept {
return ptr < other.ptr;
}

JSONIFIER_INLINE constexpr bool operator>(const array_iterator& other) const noexcept {
return other < *this;
}

JSONIFIER_INLINE constexpr bool operator<=(const array_iterator& other) const noexcept {
return !(other < *this);
}

JSONIFIER_INLINE constexpr bool operator>=(const array_iterator& other) const noexcept {
return !(*this < other);
}

pointer ptr;
};

template<typename value_type_new> class array_iterator<value_type_new, 0> {
public:
using iterator_concept = std::contiguous_iterator_tag;
using iterator_category = std::random_access_iterator_tag;
using element_type = value_type_new;
using value_type = value_type_new;
using difference_type = std::ptrdiff_t;
using pointer = value_type*;
using reference = value_type&;

JSONIFIER_INLINE constexpr array_iterator() noexcept {
}

JSONIFIER_INLINE constexpr array_iterator(std::nullptr_t ptrNew) noexcept {
}

JSONIFIER_INLINE constexpr bool operator==(const array_iterator& other) const noexcept {
return true;
}

JSONIFIER_INLINE constexpr bool operator!=(const array_iterator& other) const noexcept {
return !(*this == other);
}

JSONIFIER_INLINE constexpr bool operator>=(const array_iterator& other) const noexcept {
return !(*this < other);
}
};
namespace jsonifier::internal {

template<typename value_type_new, size_t sizeNew> struct array {
using value_type = value_type_new;
Expand Down
Loading

0 comments on commit bdea5d6

Please sign in to comment.