Repository navigation
Replies: 6 comments 7 replies
|
Sometimes I could prefer readability over performance.
|
|
The main benefit provided by lark is maintainability. Instead of hand-writing a parser, a parser is generated from a grammar. We can move forward with lark, and if performance turns out to be unacceptable, bite the bullet and hand-write something. To maximize performance the grammar should be kept as simple as possible (e.g., injecting component-specific keywords into the grammar rather than defining a grammar that is generic over all components). Perhaps consider a prospective back-compat policy for flopy4 (e.g. dfns will be supported X years or Y releases). We can be more lenient with retrospective back-compat — upon competing an initial prototype, we can test against historic dfn versions and see how far back we can support. In the long run, pursue standardizing input files with
|
|
The reason the proof of concept is so slow is the grammar is ambiguous. So lark has to use the Earley parser. For LALR the grammar can't have ambiguities. If we can get them out it should run in linear time. |
|
I think we can implement a custom xarray backend to read an input file into a dataset/tree. Internally |
|
We now have a more or less functional input file loading capability with Lark (still some edge cases to work through, but successfully loads most of the test/example models). There are two versions:
Related, superseded work I did some ASCII file benchmarking. The basic flopy4 loader is roughly competitive with flopy3, with some interesting differences.
The findings show that some of my early reasoning was wrong. The original motivation for the typed loader was multiple: better error (more specific) messages, less manual validation in transformation, and better performance. The first two points hold, but the last is probably wrong. Transformation is only taking a small (<15%) portion of the total load time. Lark lexing/parsing/etc dominates, largely due to the fact we're representing each array value as a distinct token. This blows up the size of the parse tree. It'd be faster and use less memory to parse array and list rows as a single chunk of tokens to load directly with numpy/pandas/etc. The difference between internal and external arrays demonstrates the potential for improvement here: flopy4 already bulk loads external arrays like this, but parses individual tokens for internal arrays, while flopy3 takes a sort of "middle road", parsing lines in both cases. With bulk loading everywhere, I'd expect flopy4 to be faster across the board. This shows that the basic loader probably suffices for now, and the benefit of the typed loader will mostly be clearer error messages on malformed input files. Benchmarking infra will be checked in soon |
|
some new benchmarks on 13 test models from 5 KB to 84 MB
updated after #483: all models rerun on so the next things to look at are cutting memory usage and import time on startup |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
We have discussed/prototyped using
larkto decode MF6 input files into Python containers and primitives (before passing these tocattrsfor structuring).The prototype is currently (mostly) functional. But we still need to determine how performance compares to manual decoding. This will involve benchmarking/profiling the lark prototype against flopy3. If it becomes evident that flopy3 can be optimized in fairly straightforward ways, maybe it will be useful to add a minimal hand-written decoder prototype here for better comparison.
This is related to the performance testing mentioned in #49 (comment), but the focus areas are slightly different:
All reactions