Feature: Use arena-allocation for memory handling

Arena allocation make deallocation of nested structed MUCH faster, and
improves the spatial locality of allocations. It makes no sense to
deallocate only parts of a JSON structure so arenas are a good fit here.
This commit is contained in:
olemorud
2023-05-16 02:44:49 +02:00
committed by Ole Kristian Morud
parent f58c5dcfee
commit b3821cf8bf
11 changed files with 124 additions and 97 deletions

View File

@@ -10,15 +10,18 @@ COMPILER ?= gcc
CC := gcc
# -fsanitize={address,undefined}
CFLAGS.gcc.debug := -Og -ggdb -fanalyzer -DBACKTRACE -rdynamic -fsanitize=address -fno-omit-frame-pointer
CFLAGS.gcc.debug := -Og -ggdb -DBACKTRACE -rdynamic -fanalyzer -fsanitize=address -fno-omit-frame-pointer
CFLAGS.gcc.release := -O3 -g -march=native -DNDEBUG
CFLAGS.gcc := ${CFLAGS.gcc.${BUILD}} -Iinclude -Wall -Wextra -Wpedantic -Werror -Wno-strict-aliasing -fstack-protector-all -std=gnu11
CFLAGS.gcc := ${CFLAGS.gcc.${BUILD}} -fstack-protector-all -std=gnu11 #-Wpedantic
CFLAGS.clang.debug=-O0 -g3 -DBACKTRACE -rdynamic
CFLAGS.clang.release=-O3 -g -march=native -DNDEBUG
CFLAGS.clang=-Iinclude -Wall -Wextra -Wpedantic -Werror -Wno-strict-aliasing -fstack-protector-all ${CFLAGS.clang.${BUILD}}
CFLAGS.clang=-Iinclude -Wno-strict-aliasing -fstack-protector-all ${CFLAGS.clang.${BUILD}}
CFLAGS := ${CFLAGS.${COMPILER}}
CFLAGS := ${CFLAGS.${COMPILER}} \
-Iinclude -Iarena-allocator/include \
-std=c2x \
-Wall -Wextra -Wpedantic -Werror
LD_PRELOAD:=
@@ -27,18 +30,24 @@ LD_PRELOAD:=
BUILD_DIR := bin/${BUILD}
OBJ_DIR := .obj/${BUILD}
_OBJS := main.o parse.o json_value.o util.o
_OBJS := main.o parse.o json_value.o util.o libarena.a
OBJS := $(patsubst %,$(OBJ_DIR)/%,$(_OBJS))
all : $(BUILD_DIR)/parse
$(BUILD_DIR)/parse : $(OBJS) | $(BUILD_DIR) Makefile
$(BUILD_DIR)/parse : $(OBJS) $(OBJ_DIR)/libarena.a | $(BUILD_DIR) Makefile
$(CC) $(CFLAGS) $^ $(LDFLAGS) $(LDLIBS) -o $@
$(OBJ_DIR)/main.o : src/main.c | $(OBJ_DIR) Makefile
$(OBJ_DIR)/main.o : src/main.c arena-allocator | $(OBJ_DIR) Makefile
$(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -c $< -o $@
$(OBJ_DIR)/libarena.a : arena-allocator .gitmodules $(wildcard .git/modules/arena-allocator/HEAD) | $(OBJ_DIR) Makefile
(cd arena-allocator && make static)
cp --force arena-allocator/lib/libarena.a $(OBJ_DIR)/libarena.a
arena-allocator : .gitmodules
git submodule update $@
$(OBJ_DIR)/%.o : src/%.c include/%.h | $(OBJ_DIR) Makefile
$(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -c $< -o $@