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

opt: remove some generic code bloat #2478

Merged
merged 3 commits into from
Jun 25, 2022

Conversation

davidhewitt
Copy link
Member

@davidhewitt davidhewitt commented Jun 25, 2022

Comprised of three commits when just playing around this morning:

  • Use fn instead of closure in LazyStaticType::get_or_init to avoid creating a new monomorphization of GILOnceCell::get_or_init for each PyClass
  • Use fn() instead of impl FnOnce in extract_argument default / from_py_with arguments, reducing number of monomorphizations of those functions. I think this is more correct anyway (we don't need to support capturing closures).
  • Change #[pyclass] machinery to create an iterator of PyClassItems instead of relying on a "visitor" closure. I think it's tidier, and again reduces the amount of code that needs to be generated per PyClass.

Overall this reduced llvm lines by about 2% in the pytests crate.

src/pyclass.rs Outdated Show resolved Hide resolved
src/impl_/pyclass.rs Show resolved Hide resolved
src/impl_/pyclass.rs Show resolved Hide resolved
src/impl_/extract_argument.rs Show resolved Hide resolved
@davidhewitt davidhewitt force-pushed the more-monomorphizations branch 2 times, most recently from a079a72 to 926e889 Compare June 25, 2022 10:29
@davidhewitt davidhewitt merged commit 51c0ef5 into PyO3:main Jun 25, 2022
@davidhewitt davidhewitt deleted the more-monomorphizations branch June 25, 2022 21:25
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

Successfully merging this pull request may close these issues.

None yet

2 participants