`mw.clone` is called on the global table for each new `{{#invoke:}}`,
which is a major contributor to loading times on large pages. This
change introduces various speed optimisations that make it around
15% faster:
* `recursiveClone` is declared outside of the main function, to avoid
generating a new closure each time `mw.clone` is called.
* This means `tableRefs` has to be passed as an argument to
`recursiveClone` instead of being an upvalue, which also decreases
access time.
* `recursiveClone` is only called after a `type` then `tableRefs` check
confirms a value is an unseen table, meaning it's only called when
needed, not for every key/value pair (which add noticeable overhead
when cloning large tables).
* `getmetable` is only called once, not twice, by using a local
variable.
* `tableRefs[elt]` is only accessed once, by using a ternary operator.
* Any global accesses have been replaced by local ones.
Bug: T357199
Change-Id: I51593a971f0be728255723ca300d1ce692ead256