Skip to content

Refactor Homebrew::Service to avoid shape variations #20320

@dduugg

Description

@dduugg

I propose refactoring Homebrew::Service by eagerly defining its ivars, as suggested by this warning:

/home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/service.rb:141: warning: The class Homebrew::Service reached 8 shape variations, instance variables accesses will be slower and memory usage increased.
It is recommended to define instance variables in a consistent order, for instance by eagerly defining them all in the #initialize method.

Opening an issue in case this merits further discussion (this isn't an entirely free lunch, if we're creating a bunch of ivars that aren't typically used, though I expect the impact there to be negligible).

(I don't have a ton of experience on this topic, though it was coincidentally covered in byroot's latest blog post.)

brew doctor output

N/A (CI)

Verification

  • I ran brew update twice and am still able to reproduce my issue.
  • My "brew doctor output" above says Your system is ready to brew or a definitely unrelated Tier message.
  • This issue's title and/or description do not reference a single formula e.g. brew install wget. If they do, open an issue at https://github.com/Homebrew/homebrew-core/issues/new/choose instead.

brew config output

N/A (CI)

What were you trying to do (and why)?

I opened a PR that I believe should not affect Homebrew::Service shape variations

What happened (include all command output)?

There was what I believe to be an unrelated failure, within which I noticed these lines:

/home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/service.rb:141: warning: The class Homebrew::Service reached 8 shape variations, instance variables accesses will be slower and memory usage increased.
It is recommended to define instance variables in a consistent order, for instance by eagerly defining them all in the #initialize method.

What did you expect to happen?

I expected there to be no warnings in the output of the formula audit job.

Step-by-step reproduction instructions (by running brew commands)

☝️

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions