Extremely slow execution of an external dependency function

I am using mmwr-week package. For some reason it takes about 30 seconds on average to run the following code in Realm while it takes about 0.15 seconds on my MacBook Pro:

exports = function(){
  const mmwr = require("mmwr-week");
  let mdate = new mmwr.MMWRDate();
  const d = new Date();
  for (let i = 0; i < 1000; i++) {

Any ideas why there is a ~200x difference in performance?

Hey Ilya,

There are some improvements we have planned to make dependency resolution a bit faster over the next few months. In the meantime, I would suggest looking into an alternative package if the latency is blocking.

1 Like

Hi Sumedha, just to clarify: the dependency itself is loading quickly. It’s a very simple function call (inside the loop) that is very slow.

@Sumedha_Mehta1 whatever happened here? I’m having the same issue with Stripe. It’s taking 1 minute and 15 seconds to complete a simple call to list customers by email address. The function executes quickly (including loading the dependencies with require) up until I call stripe.customers.list. This same call take < 100 ms on my local machine or within a Firebase function. Something is definitely wrong.

1 Like

@Byron_Sorrells do you have an idea of when this started happening?

Today. It’s a brand new function in a new project. I’ve also opened a support ticket and Manny is looking into it.

Did you solve your issue. could it be that when calling a third party api, realm function is getting a cors error or some sort of network issue?

No, it’s not solved. This is what I got back from support:

I was able to reproduce this on my side using your simplified code sample and it also took 1m15s for me.

After researching further I found that this is a known issue on our side when using the Stripe API in functions where requests are taking up to 50-60 seconds to complete. This is a known issue on our side with how we’re handling the Stripe request and our Engineering team are currently in the process of analysing the issue.

Unfortunately I don’t have an ETA to provide you with for when this will be fixed, however I will track the work on our side and update you in this case when there is progress.

This is extremely disappointing and leads me to believe that Realm triggers / Mongodb Functions are not production-ready as a lambda drop in replacement… I think Triggers/Realm Functions would only be suitable for Mongo Actions that require no additional third party dependencies. If stripe connections are taking more than 4 seconds to complete you have a problem. I personally am using Lambda’s and Cloudflare functions, was thinking about realm triggers but after this, i will hold off.

1 Like

Based on the reply from support, they seem to claim it’s Stripe only. I ended up not using the stripe node SDK and I wrote the requests manually using the http service. Not a huge deal and somewhat annoying, but not the end of the world. Everything works great (including the triggers).

Hi all - we’re still investigating why the stripe dependency is slower, unfortunately it’s not as straightforward to fix as hoped. I do want to call out that our dependency functionality is still in beta and if you’re having issues with them, there are immediate work arounds (such as calling the API directly). However, we’re carefully monitoring any dependency bugs that show up and filing tickets to address them. If any other part of Realm is not working as expected, please let us know!

Thanks for the quick updates @Sumedha_Mehta1. Everything else is working great. And calling the API directly works fine for now.