Question
· May 29, 2017

Globals vs Locals: What Is Faster?

Hi, colleagues!

Consider you need to put some (less  than 1GB) data to an indexed array and do some data manipulations and calculations with it.

Should I prefer global or local for it?

Is there any general rule when local is faster than global and vice-versa?

Discussion (5)1
Log in or sign up to continue

I would give you a list from fastest to slowest.

  • Local variables. Yes, this sort of variables is limited by memory, but currently, memory cost not so much and if you need only 1GB per server, it should be quite easy to get. By default, the process has only 256MB of memory for local variables, but you can extend it on a fly with special variable $zstorage, and maximum level is 2TB.
  • Process private globals (^||Global), it is already globals but works faster than any other types of globals, but slower than local variables. It is not limited by memory per process, but stored in memory, and could be moved to the disk if you exceed global buffer size.
  • Globals mapped to CACHETEMP (e.g. ^CacheTemp*, ^mtmp), such globals faster than usual globals because in this database journaling of any changes is switched off. 
  • Every other Globals, but still depends on is this database used journaling changes or if changes were made in a transaction.