Skip to content

Commit 76a5345

Browse files
committed
add parent pointer to memory pool blocks
1 parent 23a58f8 commit 76a5345

4 files changed

Lines changed: 16 additions & 3 deletions

File tree

include/pscript/memory.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <cstddef>
44
#include <memory>
55
#include <array>
6+
#include <unordered_map>
67

78
namespace ps {
89

@@ -108,7 +109,7 @@ class memory_pool {
108109
std::size_t mem_size = 0;
109110

110111
static constexpr inline std::size_t min_block_size = 16;
111-
static constexpr inline std::size_t small_block_cache_size = 8;
112+
static constexpr inline std::size_t small_block_cache_size = 32;
112113

113114
/**
114115
* @brief Represents a block in the buddy allocator.
@@ -122,6 +123,7 @@ class memory_pool {
122123

123124
std::unique_ptr<block> left = nullptr;
124125
std::unique_ptr<block> right = nullptr;
126+
block* parent = nullptr;
125127
};
126128

127129
// Root block is the initial block and represents the full memory range.

src/bench/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ std::string read_file(fs::path const& path) {
3737
}
3838

3939
int main() {
40-
constexpr std::size_t iterations = 100;
40+
constexpr std::size_t iterations = 50;
4141

4242
std::cout << std::setprecision(4);
4343
std::cout << "Benchmark\t\t||\t\tAverage runtime (milliseconds)\n";

src/pscript/memory.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,13 @@ bool memory_pool::free_block(block* root, block* parent, ps::pointer ptr) {
185185
b->left = std::make_unique<block>();
186186
b->left->ptr = b->ptr;
187187
b->left->size = new_size;
188+
b->left->parent = b;
188189

189190
// Right block starts at same pointer but offset for left block, with all leftover bytes.
190191
b->right = std::make_unique<block>();
191192
b->right->ptr = b->ptr + new_size;
192193
b->right->size = b->size - new_size;
194+
b->right->parent = b;
193195

194196
return true;
195197
}

tests/main.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1046,4 +1046,13 @@ TEST_CASE("range-for") {
10461046
ps::script script(source, ctx);
10471047
ctx.execute(script);
10481048
}
1049-
}
1049+
}
1050+
1051+
// PROFILING RESULTS
1052+
/*
1053+
* Currently, slow parts of the interpreter are
1054+
* free_block()
1055+
* node_is_type() -> Use string interning of some sorts so we dont compare string types all the time
1056+
* verify_pointer_throw()
1057+
* find_child_with_type() -> Same as node_is_type()
1058+
*/

0 commit comments

Comments
 (0)