Q: diff between declared function and delared function-variable?
Wednesday, 7 October 2026 · 2 messages · last reply 11 Oct 2026
RS
Rob Stapper7 Oct 2026 12:27 #
Hi Christian and crew,
I am thinking about changing all my function declarations:
- 'declare function <function-name>(..){...};',
to function-variable declarations:
- 'declare variable <variable-name> := fn(..){...};.
The reason for this is that function-variable declarations are easy to redirect to another function(-variable) declarations.
But before doing this I would like to know if this is a good idea: What impact would this have on performance and memory use?
What are your thoughts on this?
mvgr.
Rob Stapper
CG
Christian Grün11 Oct 2026 13:09 #
Hi Rob,
BaseX can optimize and inline static function calls more easily. Function variables may therefore be slower, especially when called frequently. Memory overhead is likely small, but the actual impact depends on your code. My recommendation: Use regular functions by default and function variables where redirection is needed.
But I’ll be interested in your benchmark results; maybe it doesn’t matter in your use case.
Best,
Christian
Quoted text · Rob Stapper · 17 lines
Rob Stapper via BaseX-Talk <basex-talk at mailman.uni-konstanz.de> schrieb am Mittwoch, 7. Oktober 2026 um 12:28: > Hi Christian and crew, > > I am thinking about changing all my function declarations: > - 'declare function <function-name>(..){...};', > to function-variable declarations: > - 'declare variable <variable-name> := fn(..){...};. > > The reason for this is that function-variable declarations are easy to redirect to another function(-variable) declarations. > > But before doing this I would like to know if this is a good idea: What impact would this have on performance and memory use? > > What are your thoughts on this? > > mvgr. > > Rob Stapper
Written for BaseX 12.4. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery