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

Efficient type identification scheme #87

Open
h33p opened this issue May 26, 2022 · 1 comment
Open

Efficient type identification scheme #87

h33p opened this issue May 26, 2022 · 1 comment

Comments

@h33p
Copy link
Contributor

h33p commented May 26, 2022

Hey there, using abi_stable I've noticed significant size requirements for performing layout checks. It appears to stem from indirection caused by accessing type IDs and layouts within TypeLayout and SharedVars through ctors. This leads to explosion of tiny functions bloating the binary/library size. If I am not mistaken, this was done due to self-referential structures and it being impossible for the compiler to deal with.

I tinkered a little bit, trying to see if one could come up with a way to support self-referential structures while staying completely in compile-time, and here is a little PoC:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=1e622b3aea8aa4437a25cae2646de820

The trick here is to have 2 type IDs, one that evaluates IDs within its type, and the other "shallow" one that skips the contents of the type. This way everything is evaluated until the last type, however, this still does not solve the self-referential cycles. The latter is solved by providing special implementations for all 4 types of indirection available in rust (mut/const references and pointers) that use only the shallow type ID. This works, because T: StableAbi implies &T: StableAbi. The example works with generating unique Type IDs, however, I think it would similarly be able to be extended over to TypeLayouts as well. Finally, it may even be possible to reduce a lot of type checking into a single stable hash value.

The question is, would the implementation of this be in your interest? I believe this would lead to positive impact to all abi_stable users and am willing to implement it, however, it would be great to do it in cooperation, as I do not want to miss out on key details regarding prefix types, reflection, etc.

@marioortizmanero
Copy link
Contributor

I would love to see this change! I'm currently working on improving the performance of my plugin system and every bit helps.

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

No branches or pull requests

2 participants