-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for user atoms and namecalls
Namecall is a mechanism in Luau to speed up method invocations. The basic idea is that the VM can cache method names (strings) to integer indices the first time it executes a method call. At this point it calls the "user atom callback" with the string. The user callback is responsible for mapping the method string to a unique 16-bit index that's returned to the VM. Next time the VM encounters the same string, it already knows how to map the string to an index as, so it will reuse the user's 16-bit index. The above is the mechanism for quickly resolving function name strings to integers. The other part of the API is using the indices. This part is the __namecall function that's attached to a (userdata) object's metatable. On a method call, the VM knows that the userdata has a registered __namecall, and calls that to dispatch to the actual user's native function to handle the native method. The namecall dispatch routine uses lua.namecallAtom() to retrieve the method name/index, which is used to select which actual native method is called. It's not very simple but it should be fast as the VM doesn't need to do a string->function hash table lookup on every method invocation. I'm not 100% sure of the details, but I suspect that the VM may also patch the bytecode (or some internal representation of it) directly with the namecall indices rather than looking them up from some string hash table.
- Loading branch information
Showing
2 changed files
with
180 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters