This is an archive of the discontinued LLVM Phabricator instance.

Optimize getters for non-atomic, copied properties
ClosedPublic

Authored by dmaclach on Jul 1 2021, 12:48 PM.

Details

Summary

Properties that were declared @property(copy, nonatomic) id foo make an unnecessary call to objc_get_property(). This call can be replaced with a direct access to the backing variable identical to how a @property(nonatomic) id foo would do it.

This reduces codegen by 4 bytes (x86_64/arm64) and removes a cross linkage unit function call per property declared as copy/nonatomic.

Diff Detail

Event Timeline

dmaclach created this revision.Jul 1 2021, 12:48 PM
dmaclach requested review of this revision.Jul 1 2021, 12:48 PM
thakis accepted this revision.Jul 9 2021, 5:38 PM
thakis added a subscriber: thakis.

Looks fine to me. Let's wait until Monday evening for rjmccall to reply, else I think this can go in.

This revision is now accepted and ready to land.Jul 9 2021, 5:38 PM
stephanemoore accepted this revision.Jul 11 2021, 7:03 AM

Looks reasonable to me.

GetSetProperty and SetPropertyAndExpressionGet are handled in the same code path for code generation for setters. The main difference seems like it should only be for the code generation for getters.

For libobjc, I expect this would replace a call to objc_getProperty with direct ivar access for non-atomic properties. As far as I know, objc_getProperty simply dereferences the ivar directly for non-atomic properties. I assume objc_getProperty has done this from the start (https://opensource.apple.com/source/objc4/objc4-371/runtime/Accessors.subproj/objc-accessors.m.auto.html is an early implementation that seems to support that assumption). Based on that, I don't anticipate any unintended change in behavior.

This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptJul 13 2021, 6:37 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript