exvcr icon indicating copy to clipboard operation
exvcr copied to clipboard

Slow

Open atomkirk opened this issue 7 years ago • 8 comments

What is causing it to be so slow? Is it exvcr itself or whatever vcr is using to intercept the network calls?

atomkirk avatar Jun 03 '17 11:06 atomkirk

Network call happens only when recording the data (first time), but method mocking (stubbing methods) on each replaying involves certain overheads. There would be rooms for improvement, but haven't been able to identify good ways.

parroty avatar Jun 05 '17 13:06 parroty

@parroty Would you mind elaborating a bit on where the speed problems ultimately reside? Is it in the mocking in meck itself? I'm asking, because it shouldn't be possible for one spec to interfere w/ another, and if you don't set clear_mock, they can. If it's possible to fix the speed, and make that the default behaviour, I think it'd be worthwhile. (I can try to help, but if you could direct me on what you alrady know about the problem, I'd appreciate it)

jeffdeville avatar Jul 02 '17 11:07 jeffdeville

I'm afraid that I haven't been able to investigate in detail. Profiling or something may be one approach.

parroty avatar Jul 02 '17 21:07 parroty

Hi,

I'm also analysing the performance of ExVCR, in my case a test with ExVCR is about 20x times slower than a test without, 230ms vs 20ms. The tests with the 3 adapters are equally slow so I think it's in the shared code. I've tried some tools to get some indicators where to look to fix the performance problem. With ExProf I got the following result on with this test: mix test test/adapter_hackney_test.exs:11. The two highest values in the uS / CALLS column are: :erlang.term_to_binary and :erlang.binary_to_term. It looks like it has something to do with the JSON Module.

Gist: https://gist.github.com/tompesman/7d15f60ccb3393cf929c608a5e081ea1

tompesman avatar Apr 09 '18 12:04 tompesman

After some more research it looks like the mock.ex file is causing the delay. The Task.await(:infinity) method is waiting for :meck.expect(module_name, function, callback) to return. Not sure why there is a delay here.

tompesman avatar Apr 17 '18 07:04 tompesman

Also really interested, some of my tests with only 2 requests take 500ms which should be almost instant when no database connections are being made.

jfrolich avatar Feb 21 '19 06:02 jfrolich

Has anyway found a work-around?

StanBright avatar Jun 23 '20 02:06 StanBright

I had the same issue with mocking, so instead mock for every cassette I implemented mocking on startup, see https://github.com/parroty/exvcr/pull/158

With this workaround, an application that heavily uses cassettes now needs 120 seconds less to run mix test

surik avatar Sep 24 '20 15:09 surik