In creating a library of custom functions, I've noticed a marked difference in performance of the same function code depending on whether the function is in the global namespace or a user-defined namespace. In at least one frustrating case of mine, the same function takes 7 times as long to execute when it is in a custom namespace, compared to the global namespace.
The difference doesn't matter in many applications, but I am using these functions on tables with 500K to 5M rows; a difference of this magnitude makes the difference between a function that is fine vs. one that is unusable.
Here some JSL that exemplifies the difference:
Names Default to Here(1);
Add Custom Functions(
globaltest = New Custom Function(
"Global",
"test123",
Function({x, y, z},
{a, b, c},
a = x;
b = y;
c = z;
Return(c)
)
)
);
Add Custom Functions(
nstest = New Custom Function(
"other",
"test123",
Function({x, y, z},
{a, b, c},
a = x;
b = y;
c = z;
Return(c)
)
)
);
For(i = 1, i <= 10000, i++,
foo = ::test123(i, i, i);
);
For(i = 1, i <= 10000, i++,
foo = other:test123(i, i, i);
);On my machine, ::test123() executes in 143 ms, whereas other:test123 takes 343 ms.
I have some functions that I'd ideally like to implement in a custom namespace or as class methods, but the overhead associated with namespace-qualification makes this untenable.
Have others have noticed this, and are there techniques/considerations that can speed up invocation of namespace-qualified functions?