Comments (8)
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.
@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.
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.
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.
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.
I've tested this with StringSegment and memory benefits are very little as long as Token instances dominate allocations.
from esprima-dotnet.
In the light of work done recently we can consider this done, right?
from esprima-dotnet.
Indeed!
from esprima-dotnet.
Related Issues (20)
- Version 3.0.0-beta-10 suffix problem HOT 10
- Import Assertions (aka Import Atributes) are back at stage 3 so we should add them again HOT 2
- Inconsistencies with ESTree HOT 1
- Keeping trivia HOT 1
- Decorator parsing is too forgiving
- Remove obsolete APIs
- Update readme HOT 5
- Issue with parsing import statement HOT 4
- IndexOutOfRangeException when parsing `#`
- Error parsing empty JSX element HOT 2
- Error parsing literal with weird characters
- Issues with optional chaining HOT 8
- Issues generating nested logical expressions HOT 1
- Issue with parsing spread operator HOT 1
- Some RegExp adaptation tests fail on NET 8 HOT 1
- Sequence expressions not formatted "correctly" HOT 2
- Minor parser issues that incorrectly pass tests
- Unable to modify Arguments Literal value from AST using AstRewriter HOT 1
- Any sample code or docs for modifying AST nodes?
- About how to easily add, delete, modify the AST node structure
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from esprima-dotnet.