Skip to content

[pull] master from google:master #234

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

Merged
merged 2 commits into from
Sep 3, 2021
Merged

[pull] master from google:master #234

merged 2 commits into from
Sep 3, 2021

Conversation

pull[bot]
Copy link

@pull pull bot commented Sep 3, 2021

See Commits and Changes for more details.


Created by pull[bot]

Can you help keep this open source service alive? 💖 Please sponsor : )

This change reduces the amount of static allocation performed during
app startup, and will potentially reduce runtime memory usage.

Both of these arrays are passed into CGPInitializeEnumType():
 - Each member of names is passed into
   JavaLangEnum_initWithNSString_withInt_() which retains the name. The
   original array itself is not persisted anywhere, and becomes
   superfluous as soon as CGPInitializeEnumType() returns - hence it's
   safe to allocate it on-demand on the stack instead of statically.
   (The allocation can occur at most once because we're inside
   +initialize and additionally guarded by a (self == concrete class)
   check, which guarantees we won't run the same thing for subclasses.)
 - Each member of int_values is likewise copied into the heap-allocated
   enum array (enumPtr in CGPInitializeEnumType), and the array itself
   is not persisted or used anywhere else. Similarly, there's no need
   to keep it alive.

In an existing app, which makes heavy use of J2ObjC protos, we have:
1488 proto enums, and 26406 cases total. Therefore we would expect a
memory consumption reduction of 26406 cases * (8 + 4 bytes) = 309KB.
It's slightly hard to measure the effect at runtime as memory tests
are inherently noisy - but we think we are able to observe a reduction
of similar order of magnitude (as measured by
task_vm_info.phys_footprint and task_vm_info.resident_size).

There is scope for further similar changes around the various J2Objc
protobuf generators in future - some changes will be equally simple
(only in cases where no pointers to these arrays are being stored after +initialize), some changes will be much more involved (pointers to the
currently static arrays inside e.g. j2objc_message are persisted forever).

PiperOrigin-RevId: 394636759
This change reduces the amount of static allocation performed during
app startup, and will potentially reduce runtime memory usage.

Both of these arrays are passed into CGPInitializeOneofCaseEnum():
 - Each member of names is passed into
   JavaLangEnum_initWithNSString_withInt_() which retains the name. The
   original array itself is not persisted anywhere, and becomes
   superfluous as soon as CGPInitializeOneofCaseEnum() returns - hence it's
   safe to allocate it on-demand on the stack instead of statically.
   (The allocation can occur at most once because we're inside
   +initialize and additionally guarded by a (self == concrete class)
   check, which guarantees we won't run the same thing for subclasses.)
 - Each member of int_values is likewise copied into the heap-allocated
   enum array (enumPtr in CGPInitializeEnumType), and the array itself
   is not persisted or used anywhere else. Similarly, there's no need
   to keep it alive.

In an existing app, which makes heavy use of J2ObjC protos, we have:
165 oneofs, and 934 cases total. Therefore we would expect a
memory consumption reduction of 934 cases * (8 + 4 bytes) = 10KB.
That's unlikely to show up in memory tests.

There is scope for further similar changes around the various J2Objc
protobuf generators in future - some changes will be equally simple
(only in cases where no pointers to these arrays are being stored after +initialize), some changes will be much more involved (pointers to the
currently static arrays inside e.g. j2objc_message are persisted forever).

PiperOrigin-RevId: 394644484
@pull pull bot added the ⤵️ pull label Sep 3, 2021
@pull pull bot merged commit 52b57ec into Mu-L:master Sep 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant