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

Add reusable accessor method for component dependencies #1826

Open
cckroets opened this issue Apr 28, 2020 · 1 comment
Open

Add reusable accessor method for component dependencies #1826

cckroets opened this issue Apr 28, 2020 · 1 comment

Comments

@cckroets
Copy link

cckroets commented Apr 28, 2020

I have recently begun splitting my project's monolith component into smaller dagger components, using Component dependencies. I expected when pulling out dependencies from the monolith into smaller ones that the code size of the generated monolith component would decrease, but it has actually increased.

Looking through the previously generated code, whenever an object Foo was accessed to create another object the component would call a private method getFoo():

private Bar getBar() {
  return new Bar(getFoo());
} 

However now every time Foo is accessed (which has been moved to another component), the precondition check is called inline:

private Bar getBarCreator() {
  return new Bar(Preconditions.checkNotNull(DaggerMonolithComponent.this.otherComponent.foo(), "Cannot return null from a non-@Nullable component method"));
} 

This same code block is duplicated hundreds of times in the component leading to longer code generation time and longer compilation time. Can we add a build optimization to generate a private accessor method that does this safety check for each component dependency used?

@Chang-Eric
Copy link
Member

Thanks, I think this is a reasonable optimization to do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants