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

On-demand feature struct allocation #696

Merged
merged 1 commit into from
Aug 19, 2024
Merged

On-demand feature struct allocation #696

merged 1 commit into from
Aug 19, 2024

Conversation

chrisdiamand
Copy link
Collaborator

Bob's conditionals in modules ("features") can use significant amounts of RAM during build.bp parsing - each config option spawns a new struct containing a copy of each build property, resulting in a multiplicative impact on memory consumption.

Fortunately, close inspection of Blueprint's "unpack" code reveals that we can instead pass in a nil pointer to the struct, instead of initialising the properties for each conditional feature, which will cause property structs to be allocated only when actually used in the build.bp file.

Use this in Bob by making the property struct for each feature a nil pointer to the property struct type, instead of a fully-instantiated interface{} wrapped in a BlueprintEmbed.

Change-Id: I42e432fcaa8f1f5cd48ba01c53cb95ce5109aa07

Copy link

github-actions bot commented Aug 19, 2024

LCOV of commit 23dbdf5 during CI #568

Summary coverage rate:
  lines......: 34.7% (4580 of 13201 lines)
  functions..: no data found
  branches...: 62.0% (556 of 897 branches)

Files changed coverage rate:
                                                 |Lines       |Functions  |Branches    
  Filename                                       |Rate     Num|Rate    Num|Rate     Num
  =====================================================================================
  core/feature.go                                |81.4%     70|    -     0|    -      0
  core/feature_test.go                           |95.2%    378|    -     0|    -      0

core/feature.go Outdated
@@ -71,20 +67,14 @@ func (f *Features) Init(properties *config.Properties, list ...interface{}) {
for i, featureName := range properties.FeatureList {
fields[i] = reflect.StructField{
Name: featurePropertyName(featureName),
Type: reflect.TypeOf(singleFeature{}),
Type: reflect.PointerTo(propsType),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we need to use PtrTo if we're still supporting go versions before 1.18

https://go.dev/pkg/reflect/?m=old#PointerTo

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep - done :)

Bob's conditionals in modules ("features") can use significant amounts
of RAM during build.bp parsing - each config option spawns a new struct
containing a copy of each build property, resulting in a multiplicative
impact on memory consumption.

Fortunately, close inspection of Blueprint's "unpack" code reveals that
we can instead pass in a nil pointer to the struct, instead of
initialising the properties for each conditional feature, which will
cause property structs to be allocated only when actually used in the
build.bp file.

Use this in Bob by making the property struct for each feature a nil
pointer to the property struct type, instead of a fully-instantiated
interface{} wrapped in a BlueprintEmbed.

Signed-off-by: Chris Diamand <chris.diamand@arm.com>
Change-Id: I42e432fcaa8f1f5cd48ba01c53cb95ce5109aa07
Copy link
Collaborator

@birunts birunts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@birunts birunts merged commit 71b1f69 into master Aug 19, 2024
34 checks passed
@birunts birunts deleted the feature_struct branch August 19, 2024 12:34
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.

3 participants