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

Allow parser customizations via protocol #203

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

DerGuteMoritz
Copy link

Had some slack time on a train ride and decided to give a patch for addressing #105 a shot.

This patch introduces the IParser protocol for customizing how values are parsed (except for booleans and null). It subsumes the already existing customization options key-fn, array-coerce-fn and *use-bigdecimals?* (see backwards-compatible-parser). For maximal performance, users should reify a parser once and share it across parser invocations. The default parser is shared by default.

Benchmarks show negligible overhead. To that end, care was taken that the existing inlineable parsers continue to be inlined when possible. Attached are the outputs of lein benchmark before and after the patch. For quick comparison, here's the mean execution times:

$ grep "time mean" before.log 
             Execution time mean : 3.440524 µs
             Execution time mean : 3.871193 µs
             Execution time mean : 43.129164 ms
             Execution time mean : 53.539673 ms
             Execution time mean : 48.274296 ms
             Execution time mean : 5.147940 µs
             Execution time mean : 161.727261 µs
             Execution time mean : 3.290368 µs
             Execution time mean : 3.334065 µs
             Execution time mean : 3.893235 µs
             Execution time mean : 3.682155 µs
             Execution time mean : 3.651921 µs
             Execution time mean : 17.229988 µs
             Execution time mean : 7.796235 µs
             Execution time mean : 8.637538 µs
$ grep "time mean" after.log  
             Execution time mean : 3.504573 µs
             Execution time mean : 3.956286 µs
             Execution time mean : 45.442353 ms
             Execution time mean : 54.671934 ms
             Execution time mean : 48.068894 ms
             Execution time mean : 5.195300 µs
             Execution time mean : 156.385378 µs
             Execution time mean : 3.484085 µs
             Execution time mean : 3.504414 µs
             Execution time mean : 3.880752 µs
             Execution time mean : 3.771605 µs
             Execution time mean : 3.629007 µs
             Execution time mean : 18.077329 µs
             Execution time mean : 7.865809 µs
             Execution time mean : 8.582887 µs

A first test serving as an example based on the usecase from #105 is included. I stopped there as a PoC to save effort in case this patch is not accepted. Otherwise, I'm happy to add more tests, some clarifying code comments and a corresponding documentation section.

This patch introduces the `IParser` protocol for customizing how values are parsed. It subsumes the
already existing customization options `key-fn`, `array-coerce-fn` and `*use-bigdecimals?*` (see
`backwards-compatible-parser`). For maximal performance, users should reify a parser once and share
it across parser invocations. The default parser is shared by default.

Benchmarks show negligible overhead. To that end, care was taken that the existing inlineable
parsers continue to be inlined when possible.
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.

1 participant