Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create custom macros for Macroize text patterns instead of invoking make_string directly #1006

Open
tgregg opened this issue Dec 4, 2024 · 0 comments
Labels
ion11 Related to Ion 1.1

Comments

@tgregg
Copy link
Contributor

tgregg commented Dec 4, 2024

          Why not just create a constant macro for it? It would be be more space efficient to have a constant macro (even if it has a multi-byte address) than it is to convert a symbol using `make_string`.

In the best case, it requires a minimum of 4 bytes to invoke make_string with a single SID. If there are more than 255 symbols, then you could have a 2-byte SID here, and if make_string is not one of the first 64 macros in the default module, then it will require 2 bytes to encode the macro address.

03      // macro `make_string`, assuming it can be invoked using a one-byte user-space address
01      // AEB - one expression present
E1 XX   // Symbol with 1-byte SID

Whereas constant macros up to (approximately) address 1MM can always be invoked using 3 or fewer bytes.

The overhead of the macro definition itself is about 4-5 bytes (1 byte to start s-expression, 2 bytes for macro symbol, 1 byte for empty signature, payload, optional 1 byte to end macro definition if using delimited sexp), so the break-even point is 5 usages or fewer in the worst case. If e.g. the constant macro is encoded with a 2 byte macro address and the SID would be 2 bytes, the break-even point is 2 usages.

Originally posted by @popematt in #990 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ion11 Related to Ion 1.1
Projects
None yet
Development

No branches or pull requests

2 participants