Comments (7)
Thanks @michalmuskala. After a few changes to commonly used combinators, I'm already at < 1MB. Closing this issue while I continue to improve things. I'll try to put in a PR later to improve the docs regarding trade-offs on inlining vs defparsec
.
from nimble_parsec.
Taking a quick look, one thing that jumps at me is the use of skip_ignored
. This is a complex combinator that is applied repeatedly in many places - this means that in each place, the entire combinator has to be compiled. Assigning a combinator to a variable and using it multiple times means it will be compiled multiple times and inlined at each use - which can be expensive for large combinators.
from nimble_parsec.
@michalmuskala What's the right way to do something like that? Use defparsec/2
and parsec/1
? Should I just do that with all the grammar entities? For some reason that felt like it would create more code rather than less (but, I've been very lax in my reading of the actual implementation).
from nimble_parsec.
Definitely on the right track; removing skip_ignored
entirely, down to 8.7M. Going to try using defparsec
instead now (I do need to skip those chars, of course). Will report that as well.
from nimble_parsec.
9.8M adding back in skip_ignored
, but converting it to defparsec/2
and parsec/1
. I'll try this with the rest of the grammar and see how things change.
(FWIW, having small combinators to test externally and use as utilities is a win anyway.)
from nimble_parsec.
Yes, using defparsec
and parsec
for commonly repeating things should decrease the code size - the parser will be compiled just once. It will be probably slightly less performant, but that needs measurements anyway.
from nimble_parsec.
This looks great @bruce! Probably the biggest grammar written with NimbleParsec so far. I would love to see how it compares speed-wise with the xrl+yrc
parser, especially because NimbleParsec doesn't require converting to a list, which should make it use less memory too.
Regarding compilation times, I have played a bit with your fork and it seems the time to compile .xrl+.yrl to beam versus nimble_parsec to beam is roughly the same right now. The .beam size of a nimble_parsec is a bit bigger though (250k vs 330k), so you did a great work on abstracting the repeated pieces with defparsec+parsec
.
from nimble_parsec.
Related Issues (20)
- Can't use remote combinators defined with defparsec HOT 7
- Library Abuse or Slow Compilation Times HOT 1
- `repeat_while` passing the wrong `context` in nested context
- Warning emitted by integer combinator HOT 3
- Add a default value to `optional` combinator HOT 2
- "Combinators are built during runtime" HOT 1
- When choice after repeat, not work HOT 2
- Fail to create combinator of consecutive repeats HOT 2
- No combinator for the beginning of a string
- MatchError from choice with integer and string. HOT 1
- Accept atoms as labels HOT 2
- Documentation: Error in second example under `repeat_while/4`
- NimbleParsec does not respect clauses order with OTP 26.0 (Elixir 1.14.4) HOT 3
- Potential "The pattern can never match the type." issue found by dialyxir HOT 3
- [proposal] Improve integer parsing HOT 2
- Add missing git tag for 1.3.1 HOT 1
- Nested parsec() call seems to consume error HOT 3
- takeP equivalent HOT 3
- Parse any character until HOT 3
- Add cheatsheet to documentation HOT 1
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 nimble_parsec.