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

Refactor internals to support realm concept #907

Merged
merged 30 commits into from Jun 16, 2021
Merged

Conversation

lahma
Copy link
Collaborator

@lahma lahma commented May 27, 2021

This PR will hopefully produce first version of Realm and Host concepts.

This will cater way for to additional features:

  • Isolated execution context, we can have custom global built and some callbacks
  • BrowserHost (or something similar) can be implemented for scenarios like AngleSharp.JS, where default environment is not what is wanted
  • Having separate initialization could also mean that we could reset the global environment without ditching the entire engine

This PR will also unify and simplify initial engine by introducing separate Intrinsics object instead having it all in Engine.

@sebastienros
Copy link
Owner

What's your feeling about how much closer it is to the specs with this PR?

@lahma
Copy link
Collaborator Author

lahma commented Jun 12, 2021

Current status is that it should now follow spec and constructs quite closely. I think that the constructs are now easier to understand and one can follow the spec with regards to references to realms (current realm etc). Tests are passing and now it's time for some polish and checking if AngleSharp custom host (Window object) can be implemented and what kind of hosting API it requires, close to finish I would say.

@lahma lahma marked this pull request as ready for review June 15, 2021 04:15
@lahma
Copy link
Collaborator Author

lahma commented Jun 15, 2021

Because this is already quite massive change I think it would be nice to get this into main before continuing the integration story via Host concepts. I've tested this API-wise against RavenDB and AngleSharp.JS, engine.Obsolete.cs helps to transition to realm and their code compiles as usual.

@lahma
Copy link
Collaborator Author

lahma commented Jun 15, 2021

Another nice outcome of making engine initialization lazier is that now one gets to run minimal scripts faster:

var engine = new Engine();
return engine.Evaluate("return [].length + ''.length").AsNumber();

Before

Method Mean Error StdDev Gen 0 Gen 1 Gen 2 Allocated
BuildEngine 5.587 us 0.0265 us 0.0207 us 1.2894 0.0687 - 21.09 KB

After

Method Mean Error StdDev Gen 0 Gen 1 Gen 2 Allocated
BuildEngine 4.312 us 0.0159 us 0.0149 us 0.8545 0.0229 - 14.04 KB

The change is more visible when the script is parsed beforehand and only the Script instance is executed against new engine:

Before

Method Mean Error StdDev Gen 0 Gen 1 Gen 2 Allocated
BuildEngine 3.323 us 0.0163 us 0.0136 us 1.0071 0.0381 - 16.48 KB

After

Method Mean Error StdDev Gen 0 Gen 1 Gen 2 Allocated
BuildEngine 2.366 us 0.0109 us 0.0102 us 0.5760 0.0153 - 9.43 KB

@lahma lahma changed the title Realms and Host Refactor internals to support realm concept Jun 15, 2021
@lahma lahma requested a review from sebastienros June 15, 2021 11:02
@lahma
Copy link
Collaborator Author

lahma commented Jun 15, 2021

@lahma lahma merged commit c55a5e4 into sebastienros:main Jun 16, 2021
@lahma lahma deleted the es6-realms branch June 16, 2021 18:33
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

Successfully merging this pull request may close these issues.

None yet

2 participants