Replies: 1 comment 3 replies
-
Hi, @shwarcu. I don't have much share in regard to performance implications caused by MSW internals. But I think what will be helpful is that MSW runs entirely client-side. We use the Service Worker as the interception and response mechanism and that's it. All the request handler declaration, processing, and client/worker communication are handled on the client. Respectively, if something blocks the main thread of your app that will also block the execution of MSW. However, based on what you've described, that's not what's happening.
Can you share some concrete examples of when this occurs? If I'm reading everything you wrote above, MSW doesn't affect the main thread at all (handlers execute quickly, etc).
I don't believe this would be possible. First, moving the logic to a web worker will imply another client/worker communication channel. That in itself introduces asynchronicity that may have a negative impact on performance aside from unblocking the main thread (things that can be synchronous would now have to be async due to the nature of messages between threads). Secondly, there is very little reason to do so. MSW in itself is not a resource-demanding library. All it does is:
I would love to hear more information about this issue from you. Maybe there is room for improvement but I need to scope it down first. Thanks. |
Beta Was this translation helpful? Give feedback.
-
MSW is fantastic library 🔥
We use it extensively in our testing setup - entire communication with API is mocked with MSW so that we can test our web app in isolation without any dependencies.
This works great when running tests on PCs (like MacBook with M1).
However when running our tests in containers in GitHub actions we noticed that our app slows down significantly and sometimes it takes ridiculous time to load.
Taking a look at network tab I can see that some requests take ridiculous amount of time (still, all requests are mocked with MSW) - like 3, 5 or more seconds.
The app is quite heavy and makes multiple requests on start. Our first though was that we incorrectly implemented msw handlers and they are executing too slowly.
So I run profiler with CPU throttling enabled and saw that handler for request (let's say)
/user
took few milliseconds but network reports that request was completed in 8 seconds.That is also confirmed by timelines inside devtools profiler - in flamegraph, block for execution of MSW handler is tiny and block for network request handled by that handler is much more longer and ends later).
Flame chart in profiler is generally filled with our app code execution with smal 'breaks' of MSW handlers execution.
I'm trying to understand what does that mean. My first assumption is that, because main thread is throttled and both app and MSW handlers are executing on main thread, we have situation that they both compete for it.
So when application code is running we can't handle requests immediately because main thread is blocked.
Is this any close to how MSW is working? Or am I totally wrong?
Do you think it's possible to move execution of MSW handlers to web worker so that they are not affected by slow execution of application code?
I would really appreciate some hints how to tackle this problem as it drives me crazy 😅
Beta Was this translation helpful? Give feedback.
All reactions