Giter VIP home page Giter VIP logo

Comments (8)

lahma avatar lahma commented on July 21, 2024

I'm leaning towards having custom TextSpan like Parlot has and then allowing span-based operations via it's Span property.

Span can be used where the methods take it as input, like number parsing, but there's so much performance overhead trying to handle Memory and span against backing string script.

from esprima-dotnet.

lahma avatar lahma commented on July 21, 2024

@Xicy I might have some prototype in some branch, I probably need to check if it's any good starting point and how far away from current main...

from esprima-dotnet.

adams85 avatar adams85 commented on July 21, 2024

I'm leaning towards having custom TextSpan like Parlot has and then allowing span-based operations via it's Span property.

Isn't TextSpan practically the same as ReadOnlyMemory<char>? Though I don't know if the underlying object needs to be accessed. If so, then there's another built in type, StringSegment in the framework.

from esprima-dotnet.

lahma avatar lahma commented on July 21, 2024

Hmm, didn't know about StringSegment, thanks for sharing. It's a bit heavy to bring a dependency package just for that though. What I remember from Memory, it brought quite the overhead, might have used it wrong too tough.

It's safe to say that original string is always around and ok to keep in memory for the lifetime of the Program (Script/Module), needs a lightweight way to access it. Memory/Span approach becomes problematic when the value needs to be stored as dictionary key (which Jint does a lot), span cannot be used as a key - TextSpan/StringSegment can. From Jint's perspective having to do .ToString() to gain usable key would make change meaningless (Memory/Span).

from esprima-dotnet.

adams85 avatar adams85 commented on July 21, 2024

What I remember from Memory, it brought quite the overhead, might have used it wrong too tough.

I'm also not an expert on (ReadOnly)Memory<T> but at first glance it just stores the same info (object, index, length) and being an ordinary struct, it can be used as dictionary key as well. Converting it to a (ReadOnly)Span<T> looks like a bit complicated though. Maybe that's where the overhead come from?

One further thing I'm aware of: Span<T> and co. have worse performance on .NET Framework than on .NET Core as they're implemented differently. Here's some additional resource on the topic. (Disclaimer: despite the similar name, I'm not the author of the article 😄)

EDIT: I consistently used Memory<T> in my comments but our use case probably would need ReadOnlyMemory<T> instead.

from esprima-dotnet.

lahma avatar lahma commented on July 21, 2024

I've tested this with StringSegment and memory benefits are very little as long as Token instances dominate allocations.

from esprima-dotnet.

adams85 avatar adams85 commented on July 21, 2024

In the light of work done recently we can consider this done, right?

from esprima-dotnet.

lahma avatar lahma commented on July 21, 2024

Indeed!

from esprima-dotnet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.