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

Cache Class::get #65

Closed
grovesNL opened this issue Jun 27, 2018 · 2 comments
Closed

Cache Class::get #65

grovesNL opened this issue Jun 27, 2018 · 2 comments

Comments

@grovesNL
Copy link

grovesNL commented Jun 27, 2018

Currently gfx spends a significant amount of time calling Class::get.

Similarly to #64, would it be possible to cache these calls somehow? Perhaps there could be a macro that provides this, like class!("NSObject").

We could try to add this to metal-rs directly for the places we need it (example), but we also need this change in other crates (for example, we frequently create NSAutoreleasePool), so it would be great if we could find a way to add this into objc.

cc @kvark @jrmuizel

@SSheldon
Copy link
Owner

SSheldon commented Jul 7, 2018

I'm working on a macro that caches the lookup, but @grovesNL it's worth noting you can avoid the lookup entirely and link the class. Like this:

extern {
    #[link_name = "OBJC_CLASS_$_NSObject"]
    static OBJC_CLASS: Class;
}
let cls = unsafe { &OBJC_CLASS }

Unfortunately I can't do that with a declarative macro because there's no way to use inputs to the macro inside the link directive. But it's doable with a procedural macro, and I've got a different macro working in objc-foundation-derive that does this.

@grovesNL
Copy link
Author

@SSheldon The new macro looks great. We'll try it out soon, thanks!

bors bot added a commit to gfx-rs/metal-rs that referenced this issue Jul 16, 2018
61: Cache class access r=kvark a=grovesNL

- Uses [objc's new `class` macro](SSheldon/rust-objc#65) to cache all class accesses
- Bumps the crate version to 0.10.3

Co-authored-by: Joshua Groves <[email protected]>
bors-servo pushed a commit to servo/core-foundation-rs that referenced this issue Jul 17, 2018
Use new objc class macro

This PR removes the `class` function in favor of the [new `class` macro exposed by objc](SSheldon/rust-objc#65) which caches access by class name. Note that this macro should eventually (through procedural macros) be able to link directly to the class.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/core-foundation-rs/226)
<!-- Reviewable:end -->
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