From 313224162ff173725d8f81b23d4e28e223abfe9e Mon Sep 17 00:00:00 2001 From: Gordon Williams Date: Fri, 6 Oct 2023 16:20:29 +0100 Subject: [PATCH] Comments about speed of ResetVariable --- scripts/profile.sh | 4 ++-- src/jsvar.c | 19 ++++++++++++------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/scripts/profile.sh b/scripts/profile.sh index 00f716afa2..78311639dd 100755 --- a/scripts/profile.sh +++ b/scripts/profile.sh @@ -5,7 +5,7 @@ # * Disable extra libs in LINUX.py # * Specify an amount of variables (2000) make clean;CFLAGS="-pg" LDFLAGS="-pg" make -./espruino benchmark/donut.js -gprof espruino > gprof.txt +bin/espruino benchmark/donut.js +gprof bin/espruino > gprof.txt cat gprof.txt diff --git a/src/jsvar.c b/src/jsvar.c index b79ddc4efc..b01e85b20b 100644 --- a/src/jsvar.c +++ b/src/jsvar.c @@ -553,11 +553,11 @@ void jsvSetCharactersInVar(JsVar *v, size_t chars) { void jsvResetVariable(JsVar *v, JsVarFlags flags) { assert((v->flags&JSV_VARTYPEMASK) == JSV_UNUSED); - // make sure we clear all data... - /* Force a proper zeroing of all data. We don't use - * memset because that'd create a function call. This - * should just generate a bunch of STR instructions */ - // FIXME: this does not generate STR instructions - it's just a tight loop with STRB. We should be able to do better? + assert(!(flags & JSV_LOCK_MASK)); + // make sure we clear all data and set 'flags'... + // Force a proper zeroing of all data. We don't use memset because that'd create a function call. + // This DOES NOT generate STR instructions - it's just a tight loop with STRB, but that seems faster. + // See below... unsigned int i; if ((sizeof(JsVar)&3) == 0) { for (i=0;iflags = flags | JSV_LOCK_ONE; + // This code really *should* be faster as it really does just + // create a handful of stores and the ARM assembly looks great. + // Somehow it's slower though! + // *v = (JsVar) { + // .varData = { }, + // .flags = flags | JSV_LOCK_ONE + //}; } JsVar *jsvNewWithFlags(JsVarFlags flags) {