Skip to content

Commit

Permalink
Comments about speed of ResetVariable
Browse files Browse the repository at this point in the history
  • Loading branch information
gfwilliams committed Oct 6, 2023
1 parent ffd2ce1 commit 3132241
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
4 changes: 2 additions & 2 deletions scripts/profile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

19 changes: 12 additions & 7 deletions src/jsvar.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;i<sizeof(JsVar)/sizeof(uint32_t);i++)
Expand All @@ -566,9 +566,14 @@ void jsvResetVariable(JsVar *v, JsVarFlags flags) {
for (i=0;i<sizeof(JsVar);i++)
((uint8_t*)v)[i] = 0;
}
// set flags
assert(!(flags & JSV_LOCK_MASK));
v->flags = 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) {
Expand Down

0 comments on commit 3132241

Please sign in to comment.