Skip to content

Commit

Permalink
Update GCutil and object value allocator for fix performance problem
Browse files Browse the repository at this point in the history
There was a problem running bubble test in web-tooling-benchmark
too many gc were occured because GC_get_bytes_since_gc() cannot track GC_free event
so, I am start to use GC_REALLOC on 64-32bit
and fixes build error with mem_stats profiler(valgrind)

Signed-off-by: Seonghyun Kim <[email protected]>
  • Loading branch information
ksh8281 authored and clover2123 committed Feb 14, 2024
1 parent c4ab1cf commit 6218b1b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 14 deletions.
2 changes: 1 addition & 1 deletion build/escargot.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ ELSEIF (${ESCARGOT_OUTPUT} STREQUAL "static_lib")
SET (ESCARGOT_THIRDPARTY_CFLAGS ${ESCARGOT_THIRDPARTY_CFLAGS} ${ESCARGOT_CXXFLAGS_STATICLIB})
ENDIF()

SET (GCUTIL_CFLAGS ${ESCARGOT_THIRDPARTY_CFLAGS})
SET (GCUTIL_CFLAGS ${ESCARGOT_THIRDPARTY_CFLAGS} ${PROFILER_FLAGS})

IF (ESCARGOT_SMALL_CONFIG)
SET (GCUTIL_CFLAGS ${GCUTIL_CFLAGS} -DSMALL_CONFIG -DMAX_HEAP_SECTS=512)
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/EncodedValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -601,13 +601,13 @@ using ObjectPropertyValue = EncodedSmallValue;
typedef ObjectPropertyValue EncodedValueVectorElement;
typedef Vector<EncodedValueVectorElement, CustomAllocator<EncodedValueVectorElement>> EncodedValueVector;
typedef TightVector<EncodedValueVectorElement, CustomAllocator<EncodedValueVectorElement>> EncodedValueTightVector;
typedef TightVectorWithNoSize<EncodedSmallValue, CustomAllocator<EncodedSmallValue>> ObjectPropertyValueVector;
typedef TightVectorWithNoSizeUseGCRealloc<EncodedSmallValue, CustomAllocator<EncodedSmallValue>> ObjectPropertyValueVector;
#else
using ObjectPropertyValue = EncodedValue;
typedef ObjectPropertyValue EncodedValueVectorElement;
typedef Vector<EncodedValueVectorElement, GCUtil::gc_malloc_allocator<EncodedValueVectorElement>> EncodedValueVector;
typedef TightVector<EncodedValueVectorElement, GCUtil::gc_malloc_allocator<EncodedValueVectorElement>> EncodedValueTightVector;
typedef TightVectorWithNoSizeUseGCRealloc<EncodedValue> ObjectPropertyValueVector;
typedef TightVectorWithNoSizeUseGCRealloc<EncodedValue, GCUtil::gc_malloc_allocator<EncodedValue>> ObjectPropertyValueVector;
#endif
} // namespace Escargot

Expand Down
2 changes: 1 addition & 1 deletion src/runtime/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ExecutionPauser;
#define OBJECT_PROPERTY_NAME_UINT32_VIAS 2
#define MAXIMUM_UINT_FOR_32BIT_PROPERTY_NAME (std::numeric_limits<uint32_t>::max() >> OBJECT_PROPERTY_NAME_UINT32_VIAS)

typedef TightVectorWithNoSizeUseGCRealloc<EncodedValue> ObjectPrivateFieldValueVector;
typedef TightVectorWithNoSizeUseGCRealloc<EncodedValue, GCUtil::gc_malloc_allocator<EncodedValue>> ObjectPrivateFieldValueVector;

struct ObjectPrivateMemberDataChain : public gc {
Object* m_contextObject;
Expand Down
34 changes: 25 additions & 9 deletions src/util/TightVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -440,24 +440,24 @@ class TightVectorWithNoSize : public gc {
T* m_buffer;
};

template <typename T>
template <typename T, typename GCAllocator>
class TightVectorWithNoSizeUseGCRealloc : public gc {
public:
TightVectorWithNoSizeUseGCRealloc()
{
m_buffer = nullptr;
}

TightVectorWithNoSizeUseGCRealloc(TightVectorWithNoSizeUseGCRealloc<T>&& other)
TightVectorWithNoSizeUseGCRealloc(TightVectorWithNoSizeUseGCRealloc<T, GCAllocator>&& other)
{
m_buffer = other.m_buffer;
other.m_buffer = nullptr;
}

TightVectorWithNoSizeUseGCRealloc(const TightVectorWithNoSizeUseGCRealloc<T>& other) = delete;
TightVectorWithNoSizeUseGCRealloc(const TightVectorWithNoSizeUseGCRealloc<T, GCAllocator>& other) = delete;

const TightVectorWithNoSizeUseGCRealloc<T>& operator=(const TightVectorWithNoSizeUseGCRealloc<T>& other) = delete;
void operator=(TightVectorWithNoSizeUseGCRealloc<T>&& other)
const TightVectorWithNoSizeUseGCRealloc<T, GCAllocator>& operator=(const TightVectorWithNoSizeUseGCRealloc<T, GCAllocator>& other) = delete;
void operator=(TightVectorWithNoSizeUseGCRealloc<T, GCAllocator>&& other)
{
if (m_buffer) {
GC_FREE(m_buffer);
Expand All @@ -483,7 +483,12 @@ class TightVectorWithNoSizeUseGCRealloc : public gc {

void pushBack(const T& val, size_t newSize)
{
T* newBuffer = (T*)GC_REALLOC(m_buffer, newSize * sizeof(T));
T* newBuffer;
if (m_buffer == nullptr) {
newBuffer = GCAllocator().allocate(newSize);
} else {
newBuffer = (T*)GC_REALLOC(m_buffer, newSize * sizeof(T));
}
newBuffer[newSize - 1] = val;
m_buffer = newBuffer;
}
Expand All @@ -506,7 +511,12 @@ class TightVectorWithNoSizeUseGCRealloc : public gc {
void resize(size_t oldSize, size_t newSize, const T& val = T())
{
if (newSize) {
T* newBuffer = (T*)GC_REALLOC(m_buffer, sizeof(T) * newSize);
T* newBuffer;
if (m_buffer == nullptr) {
newBuffer = GCAllocator().allocate(newSize);
} else {
newBuffer = (T*)GC_REALLOC(m_buffer, newSize * sizeof(T));
}

for (size_t i = oldSize; i < newSize; i++) {
newBuffer[i] = val;
Expand All @@ -521,7 +531,13 @@ class TightVectorWithNoSizeUseGCRealloc : public gc {
void resizeWithUninitializedValues(size_t oldSize, size_t newSize)
{
if (newSize) {
m_buffer = (T*)GC_REALLOC(m_buffer, newSize * sizeof(T));
T* newBuffer;
if (m_buffer == nullptr) {
newBuffer = GCAllocator().allocate(newSize);
} else {
newBuffer = (T*)GC_REALLOC(m_buffer, newSize * sizeof(T));
}
m_buffer = newBuffer;
} else {
GC_FREE(m_buffer);
m_buffer = nullptr;
Expand All @@ -541,7 +557,7 @@ class TightVectorWithNoSizeUseGCRealloc : public gc {

size_t c = end - start;
if (currentSize - c) {
T* newBuffer = (T*)GC_MALLOC((currentSize - c) * sizeof(T));
T* newBuffer = GCAllocator().allocate((currentSize - c) * sizeof(T));
VectorCopier<T>::copy(newBuffer, m_buffer, start);
VectorCopier<T>::copy(&newBuffer[end - c], &m_buffer[end], currentSize - end);

Expand Down
2 changes: 1 addition & 1 deletion third_party/GCutil
Submodule GCutil updated 2 files
+3 −1 Allocator.cpp
+2 −2 bdwgc/dbg_mlc.c

0 comments on commit 6218b1b

Please sign in to comment.