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

Consider using Box on type parameters to reduce statement allocation size #94

Open
zanieb opened this issue Jul 11, 2023 · 1 comment
Open

Comments

@zanieb
Copy link
Contributor

zanieb commented Jul 11, 2023

In #93, we add type_params: Vec to ClassDef and FunctionDef which increases the size of a statement. We may want to optimize this field to reduce the size of the statement struct.

The main reason for the assertion is to be aware of how changing the AST changes its size. This is important because ruff and RustPython hold many instances of these types and increasing their size mean:

  • Each element in a Vec now requires more storage -> Overall increased memory consumption
  • Reading or writing an element becomes slower because your computer must read or write more bytes. This is especially relevant for reading where the L1 cache short circuits reads by caching about 64 bytes of neighboring memory to avoid subsequent reads from (the very slow) memory.

There's not much we can do about this here. This could be a place where using tinyvec over a regular Vec would be beneficial, considering that the vec will be empty for almost all instances. But I think this is fine for now.

Originally posted by @MichaReiser in #93 (comment)

@zanieb
Copy link
Contributor Author

zanieb commented Aug 1, 2023

Best implemented once Box matching is available in stable rust (nightly at the time of this comment).

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

1 participant