Improving performance when creating many mocks #520
-
Hi! We've been using mockery for a while now, and the team absolutely loves it. Thank you for the open contribution! We decided to put the generation of mocks in a pre-commit hook to ensure tests would always pass. However, as adoption has grown though, we've noticed that generation grows slower due to the sequential nature of the generation. Do you know if there are any easy ways to improve this? I'm aware that the v3 take attempts to tackle this, but I was wondering if you know of any potential soothers until that comes out. Cheers! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Unfortunately there are not many. The main problem comes from yet it doesn't help much. This is also not a problem unique to mockery: Here's an explanation of the problem: golang/go#31087 One of the other potential issues is that Notice this call here: Line 56 in 847d988 This method is called once for every file in your repo! https://github.com/vektra/mockery/blob/v2.15.0/pkg/parse.go#L100 No wonder it's slow! The way I envision this for v3 is that you will specify which packages you want loaded in config, instead of having the code auto-discover (although maybe that could still be a feature). That way, we'd make one call to Until either of those code changes are done, there's not much we can do. But, I think in theory the fix for v2 is pretty simple and could be done without a lot of headache. |
Beta Was this translation helpful? Give feedback.
-
Note that this issue should be fixed if you are using the |
Beta Was this translation helpful? Give feedback.
Unfortunately there are not many. The main problem comes from
packages.Load
which is doing the actual AST parsing. There have been various hacks suggested that I didn't like for various reasons. We've done what the maintainers have suggested with caching the Loads to avoid re-parsing the same thing multiple times: https://github.com/vektra/mockery/blob/v2.15.0/pkg/parse.go#L53yet it doesn't help much. This is also not a problem unique to mockery:
golang/go#31087
cogentcore/cogent#150
Here's an explanation of the problem: golang/go#31087
One of the other potential issues is that
packages.Load
is loading the entire dep tree of every single file in your package, which would mean parsing the…