Static symbol table

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Static symbol table

Vee Kay
Hello,

I am using a symbol table to map chars to my own struct. This works well, however, all of my symbols are known at compile-time; whereas the symbol table can be modified at run time as far as I know. I was therefore wondering if I am paying for something I do not use and whether there is a recommended alternative?
Thank you,

Albert

------------------------------------------------------------------------------

_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: Static symbol table

sehe
On 20-12-15 21:33, Vee Kay wrote:

I am using a symbol table to map chars to my own struct. This works well, however, all of my symbols are known at compile-time; whereas the symbol table can be modified at run time as far as I know. I was therefore wondering if I am paying for something I do not use and whether there is a recommended alternative?
Symbol tables are pretty efficient but indeed runtime dynamic. (Note that efficient does not imply super-fast: The qi::symbols<> approach is surprisingly fast: Live On Coliru. I had a recent optimization job where it disappointed: see this answer (under "Spirit (Trie)") – Binary String to Hex)

It could mostly be an issue if you build your symbols each time (don't, just use the same (const) instance of your grammar each time).

Out of the box, if your symbols are things like keywords, you might want to recognize them as tokens.

Spirit Lex has a statically generated tokenizer: http://www.boost.org/doc/libs/1_60_0/libs/spirit/doc/html/spirit/lex/abstracts/lexer_static_model.html which generates code statically, instead of compiling token definitions at runtime.

It's hard to tell whether this would be a good fit for your use case, but it certainly wouldn't get structurally faster than this.

Seth

------------------------------------------------------------------------------

_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: Static symbol table

Joel de Guzman
On 12/21/15 8:49 AM, Seth wrote:

> On 20-12-15 21:33, Vee Kay wrote:
>>
>> I am using a symbol table to map chars to my own struct. This works well, however, all
>> of my symbols are known at compile-time; whereas the symbol table can be modified at run
>> time as far as I know. I was therefore wondering if I am paying for something I do not
>> use and whether there is a recommended alternative?
> Symbol tables are pretty efficient but indeed runtime dynamic. (Note that efficient does
> not imply super-fast: /The qi::symbols<> approach is surprisingly fast: //Live On Coliru
> <http://coliru.stacked-crooked.com/a/81a85f4c3b8fc610>//. I had a recent optimization job
> where it disappointed: see this answer (under "Spirit (Trie)") –////Binary String to Hex
> <http://stackoverflow.com/questions/29210120/binary-string-to-hex-c/29214966#29214966>/)<http://stackoverflow.com/questions/29210120/binary-string-to-hex-c/29214966#29214966>
>
> It could mostly be an issue if you build your symbols each time (don't, just use the same
> (const) instance of your grammar each time).

"The qi::symbols<> approach is surprisingly fast" Did you mean
surprisingly slow?

Could you provide a the benchmark in a form that I can easily try?
I'd like to try it and possibly add the benchmark to our workbench
tests.

I think there's something amiss here. The phoenix semantic action
is one suspect. Have you tried betting rid of the action? Also the
TST actually has an undocumented feature that allows you to use a hash
map in conjunction with the trie. It would be good to bring that to
light.

Regards,
--
Joel de Guzman
http://www.ciere.com
http://boost-spirit.com
http://www.cycfi.com/


------------------------------------------------------------------------------
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: Static symbol table

Joel de Guzman
On 12/23/15 7:55 AM, Joel de Guzman wrote:

> On 12/21/15 8:49 AM, Seth wrote:
>> On 20-12-15 21:33, Vee Kay wrote:
>>>
>>> I am using a symbol table to map chars to my own struct. This works well, however, all
>>> of my symbols are known at compile-time; whereas the symbol table can be modified at run
>>> time as far as I know. I was therefore wondering if I am paying for something I do not
>>> use and whether there is a recommended alternative?
>> Symbol tables are pretty efficient but indeed runtime dynamic. (Note that efficient does
>> not imply super-fast: /The qi::symbols<> approach is surprisingly fast: //Live On Coliru
>> <http://coliru.stacked-crooked.com/a/81a85f4c3b8fc610>//. I had a recent optimization job
>> where it disappointed: see this answer (under "Spirit (Trie)") –////Binary String to Hex
>> <http://stackoverflow.com/questions/29210120/binary-string-to-hex-c/29214966#29214966>/)<http://stackoverflow.com/questions/29210120/binary-string-to-hex-c/29214966#29214966>
>>
>> It could mostly be an issue if you build your symbols each time (don't, just use the same
>> (const) instance of your grammar each time).
>
> "The qi::symbols<> approach is surprisingly fast" Did you mean
> surprisingly slow?
>
> Could you provide a the benchmark in a form that I can easily try?
> I'd like to try it and possibly add the benchmark to our workbench
> tests.
>
> I think there's something amiss here. The phoenix semantic action
> is one suspect. Have you tried betting rid of the action? Also the
> TST actually has an undocumented feature that allows you to use a hash
> map in conjunction with the trie. It would be good to bring that to
> light.

Whoa! Lots of string allocation/deallocation in the disassembly there
what's happening? Are you adding the TST creation to the total test
time?

Regards,
--
Joel de Guzman
http://www.ciere.com
http://boost-spirit.com
http://www.cycfi.com/


------------------------------------------------------------------------------
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: Static symbol table

Vee Kay
In reply to this post by sehe
On Mon, Dec 21, 2015 at 12:49 AM, Seth <[hidden email]> wrote:
[...]


Hello,

Thank for the reply.
It also seems I can do

a >> attr(1)

to map a to 1. Would you have any insights as to whether this is a good practice and/or how it performances performance-wise?

Albert

------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general