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 SkipAcyclicVerification Option, and container.VerifyAcyclic #209

Merged
merged 13 commits into from
Sep 19, 2018

Conversation

dnathe4th
Copy link
Contributor

It is not unreasonable for libraries using dig under the hood for dependency graph management to c.Provide constructors in a tight loop. Rather than paying the cost of of verifying the graph is acyclic for every Provide, this option and method combination can be used to verify the graph once, after the loop has completed.

dig.go Outdated Show resolved Hide resolved
dig.go Outdated Show resolved Hide resolved
dig.go Outdated Show resolved Hide resolved
dig.go Outdated
@@ -211,6 +217,20 @@ func New(opts ...Option) *Container {
return c
}

// DeferAcyclicVerification is an Option to override the default behavior
// of container.Provide, disabling the validation the dependency graph remains

Choose a reason for hiding this comment

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

nit: this comment needs updating. Otherwise looks good to me. I didn't thoroughly verify the correctness of your code, I'll leave that to the folks who actually own dig and know the internals better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I actually did rewrite this a bit. Is your objection to the word "disabling"? I think my sentence is confusing. This one combined with the last sentence in the comment block is intended to indicate the container will no longer validate on each Provide, but it will before the first Invoke.

dig_test.go Outdated Show resolved Hide resolved
dig.go Outdated Show resolved Hide resolved
dig.go Outdated Show resolved Hide resolved
dig.go Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Sep 18, 2018

Codecov Report

Merging #209 into master will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #209      +/-   ##
==========================================
+ Coverage   98.81%   98.83%   +0.02%     
==========================================
  Files           9        9              
  Lines        1010     1034      +24     
==========================================
+ Hits          998     1022      +24     
  Misses         10       10              
  Partials        2        2
Impacted Files Coverage Δ
cycle.go 100% <100%> (ø) ⬆️
dig.go 98.76% <100%> (+0.1%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dc2d8c6...bca8e93. Read the comment docs.

@codecov
Copy link

codecov bot commented Sep 18, 2018

Codecov Report

Merging #209 into master will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #209      +/-   ##
==========================================
+ Coverage   98.81%   98.83%   +0.02%     
==========================================
  Files           9        9              
  Lines        1010     1033      +23     
==========================================
+ Hits          998     1021      +23     
  Misses         10       10              
  Partials        2        2
Impacted Files Coverage Δ
cycle.go 100% <100%> (ø) ⬆️
dig.go 98.73% <100%> (+0.08%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dc2d8c6...bca8e93. Read the comment docs.

1 similar comment
@codecov
Copy link

codecov bot commented Sep 18, 2018

Codecov Report

Merging #209 into master will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #209      +/-   ##
==========================================
+ Coverage   98.81%   98.83%   +0.02%     
==========================================
  Files           9        9              
  Lines        1010     1033      +23     
==========================================
+ Hits          998     1021      +23     
  Misses         10       10              
  Partials        2        2
Impacted Files Coverage Δ
cycle.go 100% <100%> (ø) ⬆️
dig.go 98.73% <100%> (+0.08%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dc2d8c6...bca8e93. Read the comment docs.

@codecov
Copy link

codecov bot commented Sep 18, 2018

Codecov Report

Merging #209 into master will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #209      +/-   ##
==========================================
+ Coverage   98.81%   98.83%   +0.02%     
==========================================
  Files           9        9              
  Lines        1010     1033      +23     
==========================================
+ Hits          998     1021      +23     
  Misses         10       10              
  Partials        2        2
Impacted Files Coverage Δ
cycle.go 100% <100%> (ø) ⬆️
dig.go 98.73% <100%> (+0.08%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dc2d8c6...51b1fc5. Read the comment docs.

3 similar comments
@codecov
Copy link

codecov bot commented Sep 18, 2018

Codecov Report

Merging #209 into master will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #209      +/-   ##
==========================================
+ Coverage   98.81%   98.83%   +0.02%     
==========================================
  Files           9        9              
  Lines        1010     1033      +23     
==========================================
+ Hits          998     1021      +23     
  Misses         10       10              
  Partials        2        2
Impacted Files Coverage Δ
cycle.go 100% <100%> (ø) ⬆️
dig.go 98.73% <100%> (+0.08%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dc2d8c6...51b1fc5. Read the comment docs.

@codecov
Copy link

codecov bot commented Sep 18, 2018

Codecov Report

Merging #209 into master will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #209      +/-   ##
==========================================
+ Coverage   98.81%   98.83%   +0.02%     
==========================================
  Files           9        9              
  Lines        1010     1033      +23     
==========================================
+ Hits          998     1021      +23     
  Misses         10       10              
  Partials        2        2
Impacted Files Coverage Δ
cycle.go 100% <100%> (ø) ⬆️
dig.go 98.73% <100%> (+0.08%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dc2d8c6...51b1fc5. Read the comment docs.

@codecov
Copy link

codecov bot commented Sep 18, 2018

Codecov Report

Merging #209 into master will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #209      +/-   ##
==========================================
+ Coverage   98.81%   98.83%   +0.02%     
==========================================
  Files           9        9              
  Lines        1010     1033      +23     
==========================================
+ Hits          998     1021      +23     
  Misses         10       10              
  Partials        2        2
Impacted Files Coverage Δ
cycle.go 100% <100%> (ø) ⬆️
dig.go 98.73% <100%> (+0.08%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dc2d8c6...51b1fc5. Read the comment docs.

dig.go Outdated Show resolved Hide resolved
cycle.go Outdated Show resolved Hide resolved
cycle_test.go Outdated Show resolved Hide resolved
dig.go Outdated Show resolved Hide resolved
dig.go Outdated
}
}

c.isVerifiedAcyclic = true
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: I would set this in the if clause above where you're checking it so
that it reads like this:

if !isVerified {
  verify()
  isVerified = true
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure I agree. The if clause above is only testing starting from a single node. We don't really know that the container is verifiably acyclic until after all nodes have been tested.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, my comment may have been confusing. I was talking about the one in Invoke.

if !c.isVerifiedAcyclic {
    if err := c.verifyAcyclic(); err != nil {
        return err
    }
}

Right now, we check isVerifiedAcyclic in Invoke, then verifyAcylic sets it.
I'm suggesting,

if !c.isVerifiedAcyclic {
    if err := c.verifyAcyclic(); err != nil {
        return err
    }
    c.isVerifiedAcyclic = true
}

dig.go Outdated Show resolved Hide resolved
dig_test.go Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Sep 19, 2018

Codecov Report

Merging #209 into master will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #209      +/-   ##
==========================================
+ Coverage   98.81%   98.83%   +0.02%     
==========================================
  Files           9        9              
  Lines        1010     1033      +23     
==========================================
+ Hits          998     1021      +23     
  Misses         10       10              
  Partials        2        2
Impacted Files Coverage Δ
cycle.go 100% <100%> (ø) ⬆️
dig.go 98.73% <100%> (+0.08%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dc2d8c6...e81e5bf. Read the comment docs.

@codecov
Copy link

codecov bot commented Sep 19, 2018

Codecov Report

Merging #209 into master will increase coverage by 0.12%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #209      +/-   ##
==========================================
+ Coverage   98.81%   98.93%   +0.12%     
==========================================
  Files           9        9              
  Lines        1010     1032      +22     
==========================================
+ Hits          998     1021      +23     
+ Misses         10        9       -1     
  Partials        2        2
Impacted Files Coverage Δ
cycle.go 100% <100%> (ø) ⬆️
dig.go 98.73% <100%> (+0.07%) ⬆️
error.go 100% <0%> (+0.86%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dc2d8c6...e81e5bf. Read the comment docs.

@codecov
Copy link

codecov bot commented Sep 19, 2018

Codecov Report

Merging #209 into master will increase coverage by 0.12%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #209      +/-   ##
==========================================
+ Coverage   98.81%   98.93%   +0.12%     
==========================================
  Files           9        9              
  Lines        1010     1032      +22     
==========================================
+ Hits          998     1021      +23     
+ Misses         10        9       -1     
  Partials        2        2
Impacted Files Coverage Δ
cycle.go 100% <100%> (ø) ⬆️
dig.go 98.73% <100%> (+0.07%) ⬆️
error.go 100% <0%> (+0.86%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dc2d8c6...868667b. Read the comment docs.

3 similar comments
@codecov
Copy link

codecov bot commented Sep 19, 2018

Codecov Report

Merging #209 into master will increase coverage by 0.12%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #209      +/-   ##
==========================================
+ Coverage   98.81%   98.93%   +0.12%     
==========================================
  Files           9        9              
  Lines        1010     1032      +22     
==========================================
+ Hits          998     1021      +23     
+ Misses         10        9       -1     
  Partials        2        2
Impacted Files Coverage Δ
cycle.go 100% <100%> (ø) ⬆️
dig.go 98.73% <100%> (+0.07%) ⬆️
error.go 100% <0%> (+0.86%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dc2d8c6...868667b. Read the comment docs.

@codecov
Copy link

codecov bot commented Sep 19, 2018

Codecov Report

Merging #209 into master will increase coverage by 0.12%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #209      +/-   ##
==========================================
+ Coverage   98.81%   98.93%   +0.12%     
==========================================
  Files           9        9              
  Lines        1010     1032      +22     
==========================================
+ Hits          998     1021      +23     
+ Misses         10        9       -1     
  Partials        2        2
Impacted Files Coverage Δ
cycle.go 100% <100%> (ø) ⬆️
dig.go 98.73% <100%> (+0.07%) ⬆️
error.go 100% <0%> (+0.86%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dc2d8c6...868667b. Read the comment docs.

@codecov
Copy link

codecov bot commented Sep 19, 2018

Codecov Report

Merging #209 into master will increase coverage by 0.12%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #209      +/-   ##
==========================================
+ Coverage   98.81%   98.93%   +0.12%     
==========================================
  Files           9        9              
  Lines        1010     1032      +22     
==========================================
+ Hits          998     1021      +23     
+ Misses         10        9       -1     
  Partials        2        2
Impacted Files Coverage Δ
cycle.go 100% <100%> (ø) ⬆️
dig.go 98.73% <100%> (+0.07%) ⬆️
error.go 100% <0%> (+0.86%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dc2d8c6...868667b. Read the comment docs.

@codecov
Copy link

codecov bot commented Sep 19, 2018

Codecov Report

Merging #209 into master will increase coverage by 0.12%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #209      +/-   ##
==========================================
+ Coverage   98.81%   98.93%   +0.12%     
==========================================
  Files           9        9              
  Lines        1010     1032      +22     
==========================================
+ Hits          998     1021      +23     
+ Misses         10        9       -1     
  Partials        2        2
Impacted Files Coverage Δ
cycle.go 100% <100%> (ø) ⬆️
dig.go 98.73% <100%> (+0.07%) ⬆️
error.go 100% <0%> (+0.86%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dc2d8c6...868667b. Read the comment docs.

1 similar comment
@codecov
Copy link

codecov bot commented Sep 19, 2018

Codecov Report

Merging #209 into master will increase coverage by 0.12%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #209      +/-   ##
==========================================
+ Coverage   98.81%   98.93%   +0.12%     
==========================================
  Files           9        9              
  Lines        1010     1032      +22     
==========================================
+ Hits          998     1021      +23     
+ Misses         10        9       -1     
  Partials        2        2
Impacted Files Coverage Δ
cycle.go 100% <100%> (ø) ⬆️
dig.go 98.73% <100%> (+0.07%) ⬆️
error.go 100% <0%> (+0.86%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dc2d8c6...868667b. Read the comment docs.

@dnathe4th dnathe4th changed the title Add SkipAcyclicVerification ProvideOption, and container.VerifyAcyclic Add SkipAcyclicVerification Option, and container.VerifyAcyclic Sep 19, 2018
@codecov
Copy link

codecov bot commented Sep 19, 2018

Codecov Report

Merging #209 into master will increase coverage by 0.12%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #209      +/-   ##
==========================================
+ Coverage   98.81%   98.93%   +0.12%     
==========================================
  Files           9        9              
  Lines        1010     1032      +22     
==========================================
+ Hits          998     1021      +23     
+ Misses         10        9       -1     
  Partials        2        2
Impacted Files Coverage Δ
cycle.go 100% <100%> (ø) ⬆️
dig.go 98.73% <100%> (+0.07%) ⬆️
error.go 100% <0%> (+0.86%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5bfd7bc...7596db5. Read the comment docs.

1 similar comment
@codecov
Copy link

codecov bot commented Sep 19, 2018

Codecov Report

Merging #209 into master will increase coverage by 0.12%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #209      +/-   ##
==========================================
+ Coverage   98.81%   98.93%   +0.12%     
==========================================
  Files           9        9              
  Lines        1010     1032      +22     
==========================================
+ Hits          998     1021      +23     
+ Misses         10        9       -1     
  Partials        2        2
Impacted Files Coverage Δ
cycle.go 100% <100%> (ø) ⬆️
dig.go 98.73% <100%> (+0.07%) ⬆️
error.go 100% <0%> (+0.86%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5bfd7bc...7596db5. Read the comment docs.

@codecov
Copy link

codecov bot commented Sep 19, 2018

Codecov Report

Merging #209 into master will increase coverage by 0.12%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #209      +/-   ##
==========================================
+ Coverage   98.81%   98.93%   +0.12%     
==========================================
  Files           9        9              
  Lines        1010     1032      +22     
==========================================
+ Hits          998     1021      +23     
+ Misses         10        9       -1     
  Partials        2        2
Impacted Files Coverage Δ
cycle.go 100% <100%> (ø) ⬆️
dig.go 98.73% <100%> (+0.07%) ⬆️
error.go 100% <0%> (+0.86%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5bfd7bc...e3d6f84. Read the comment docs.

@abhinav abhinav merged commit 8f0cac8 into uber-go:master Sep 19, 2018
abhinav added a commit that referenced this pull request Sep 19, 2018
abhinav pushed a commit that referenced this pull request Sep 19, 2018
This adds a DeferAcyclicVerification option which defers cycle detection
until the first invoke.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants