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

Slow initialization when getting Jint instance #72

Open
bakkar1989 opened this issue Nov 22, 2020 · 1 comment
Open

Slow initialization when getting Jint instance #72

bakkar1989 opened this issue Nov 22, 2020 · 1 comment
Milestone

Comments

@bakkar1989
Copy link

I am trying to make use of Jint object to pass a custom variable from c# to javascript.

When calling the method "GetOrCreateJint" to get the instance it slows down by 300 - 400 ms on my laptop.

Also i tried to create 100 instances to use as pooling but its taking over 2GB of memory.

Are these two scenarios expected or there is a workaround?

 static List<(IDocument Dom, Engine Js)> engineList = new List<(IDocument Dom, Engine Js)>();
     public static void TestSpeed()
     {
         for (int i = 0; i < 100; i++)
         {
             Stopwatch sw = new Stopwatch();
             sw.Start();
             var config = Configuration.Default.WithJs();
             var context = BrowsingContext.New(config);
             
             var jsEngine = context.GetService<JsScriptingService>();

             var doc = context.OpenAsync(req => req.Content("<html><head></head><body></body></html>")).Result;
             
             // slow loading
             var engine = jsEngine.GetOrCreateJint(doc);

             engine.SetValue("myVar", "value");

             // 100 instances == 2Gb Memory
             engineList.Add((doc, engine));

             sw.Stop();
             Console.WriteLine(i + " - " + sw.ElapsedMilliseconds);
         }
         Console.ReadLine();
     }
@FlorianRappl
Copy link
Contributor

There is quite some lookup and mapping done when the whole instance is scaffolded. Depending on your .NET runtime this may take a while.

So its expected to eat memory and to take a while. I guess it could be reduced a bit, but not by much as some of the boundary conditions (managed code, dynamic integration, interpreter) cannot be taken away.

@FlorianRappl FlorianRappl added this to the v1.0 milestone Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants