Quantcast

Are Parboiled for Scala Parsers thread-safe?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Are Parboiled for Scala Parsers thread-safe?

chrisl
The wiki page on Parboiled thread-safety, https://github.com/sirthias/parboiled/wiki/Thread-Safety, mentions that the Java parser is not thread-safe.

Does this also apply to a Parboiled for Scala parser? How can one optimize (re)creation of these? (I have a server application that does large numbers of concurrent parses, over the entire application lifetime).
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Are Parboiled for Scala Parsers thread-safe?

chrisl
PS. I'm currently using it in this manner, with a fairly extensive grammar, and haven't noticed any issues. But I want to be sure.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Are Parboiled for Scala Parsers thread-safe?

mathias
Administrator
Chris,

the source of non-thread-safety in parboiled parsers stems from operations that are side-effecting onto things living outside of the MatcherContext.
In parboiled for Java the BaseParser class extends `BaseActions`, which has a mutable field holding the context for the current action:
https://github.com/sirthias/parboiled/blob/master/parboiled-java/src/main/java/org/parboiled/BaseActions.java#L49

This makes a parboiled-for-Java parser non-thread-safe.

parboiled for Scala parsers don't have this problem and *should* be thread-safe. However, I have to admit that, when I added the scala-side wrapper around the previously existing java sources, I did not check carefully enough whether there are other areas for thread-safety problems.
You already identified one of these with https://github.com/sirthias/parboiled/pull/58.

So, I don't know of any reason (apart from the one you found), why a parboiled-for-Scala parser should not be thread-safe (if you stick to the rules in your own parser actions), but there *might* be others. YMMV.

Note: we are in the process of starting a much improved Scala-only rewrite of parboiled, which will keep the DSL almost identical but rely on Scala 2.10 macros to generate the code for the parser rules at compile time. This "parboiled 2.0" version will drop support for Java, but give the Scala side a significant performance boost, since the parser rules will be executed directly in byte code rather than being interpreted by a rule engine. It will also be much cleaner, more lightweight and more flexible.
If you are not currently relying on the RecoveringParserRunner (which we will not include with the initial version of parboiled 2.0) I think you'll probably want to upgrade as soon as the new version is done.

Cheers,
Mathias

---
[hidden email]
http://www.parboiled.org

On 22.04.2013, at 19:44, "chrisl [via parboiled users]" <[hidden email]> wrote:

>
>
> PS. I'm currently using it in this manner, with a fairly extensive grammar,
> and haven't noticed any issues. But I want to be sure.
>
>
>
> _______________________________________________
> If you reply to this email, your message will be added to the discussion below:
> http://users.parboiled.org/Are-Parboiled-for-Scala-Parsers-thread-safe-tp4024177p4024178.html
> To start a new topic under parboiled users, email [hidden email]
> To unsubscribe from parboiled users, visit
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Are Parboiled for Scala Parsers thread-safe?

chrisl
Thanks Mattias.

Based on my testing thus far, it seems to be fine. And given the performance difference is orders of magnitude, I'm going to keep using the scala parser in this manner.

If anyone does find a problem, then I'd love that information.

Also - is there a timeframe for parboiled 2.0?

Cheers,
Chris
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Are Parboiled for Scala Parsers thread-safe?

tsuckow

:'(

Recovering parse runner, you will be missed. Not that I can complain, I haven't had time to work on my project that used it. It also isn't really required, though it is nice.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Are Parboiled for Scala Parsers thread-safe?

mathias
Administrator
@chrisl: there is not yet a timeframe, but we are working on it already and don't expect things to take too long.
Current ETA is sometime this summer.

@tsuckow: We want to prioritize features somewhat, and the RecoveringParseRunner has relatively high complexity and only limited applicability (many projects do not require it). We therefore moved it down the prio list..

Cheers,
Mathias

---
[hidden email]
http://www.parboiled.org

On 23.04.2013, at 02:31, tsuckow [via parboiled users] <[hidden email]> wrote:

>
>
> :'(
>
> Recovering parse runner, you will be missed. Not that I can complain, I
> haven't had time to work on my project that used it. It also isn't really
> required, though it is nice.
>
>
>
>
> _______________________________________________
> If you reply to this email, your message will be added to the discussion below:
> http://users.parboiled.org/Are-Parboiled-for-Scala-Parsers-thread-safe-tp4024177p4024181.html
> To start a new topic under parboiled users, email [hidden email]
> To unsubscribe from parboiled users, visit
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Are Parboiled for Scala Parsers thread-safe?

tsuckow
Mathias,

That's completely understandable.

You have a great library, keep up the good work.

-
Thomas
Thomas Suckow


On Tue, Apr 23, 2013 at 12:46 AM, mathias [via parboiled users]
<[hidden email]> wrote:

> @chrisl: there is not yet a timeframe, but we are working on it already and
> don't expect things to take too long.
> Current ETA is sometime this summer.
>
> @tsuckow: We want to prioritize features somewhat, and the
> RecoveringParseRunner has relatively high complexity and only limited
> applicability (many projects do not require it). We therefore moved it down
> the prio list..
>
> Cheers,
> Mathias
>
> ---
> [hidden email]
> http://www.parboiled.org
>
> On 23.04.2013, at 02:31, tsuckow [via parboiled users] <[hidden email]>
> wrote:
>
>>
>>
>> :'(
>>
>> Recovering parse runner, you will be missed. Not that I can complain, I
>> haven't had time to work on my project that used it. It also isn't really
>> required, though it is nice.
>>
>>
>>
>>
>> _______________________________________________
>> If you reply to this email, your message will be added to the discussion
>> below:
>>
>> http://users.parboiled.org/Are-Parboiled-for-Scala-Parsers-thread-safe-tp4024177p4024181.html
>> To start a new topic under parboiled users, email [hidden email]
>> To unsubscribe from parboiled users, visit
>
> ________________________________
> If you reply to this email, your message will be added to the discussion
> below:
> http://users.parboiled.org/Are-Parboiled-for-Scala-Parsers-thread-safe-tp4024177p4024182.html
> To start a new topic under parboiled users, email
> [hidden email]
> To unsubscribe from parboiled users, click here.
> NAML
Loading...