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

performance of parser #205

Open
pke opened this issue Feb 21, 2017 · 9 comments
Open

performance of parser #205

pke opened this issue Feb 21, 2017 · 9 comments
Assignees
Labels
status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation. type: feature Introduction of new functionality.

Comments

@pke
Copy link

pke commented Feb 21, 2017

I profiled my normalization function that creates about 120 opening_hour objects and it takes a whopping 3 seconds. Is there a way to speed that up? Has the parser been optimized for performance yet?
I might move the creation of those objects to a worker so that the main app thread is not blocked.

@ypid ypid added the type: feature Introduction of new functionality. label Feb 21, 2017
@ypid ypid added this to the world conquest milestone Feb 21, 2017
@ypid
Copy link
Member

ypid commented Feb 21, 2017

Not much work has gone into performance optimizations yet.

@pke
Copy link
Author

pke commented Feb 21, 2017

Ok, then I'll risk a deeper look with the profiler.

@ypid ypid assigned pke Mar 6, 2017
ypid added a commit to ypid/opening_hours.js that referenced this issue Mar 6, 2017
This has been achieved by using a dictionary to quickly lookup common
literals to get their corresponding tokens.

Related to: opening-hours#205
@ypid
Copy link
Member

ypid commented Mar 6, 2017

I read a part of the implementation and it looked rather inefficient. To make it short, #213 contains a patch which improves common constructor calls by factor 6. I expect more such inefficiencies. Note that I started with this project without any prior JavaScript knowledge and not so much programming experience back then. Also JavaScript is not really my main programming language (currently Python I would say).

Ok, then I'll risk a deeper look with the profiler.

Looking forward to your pull requests 😉

@pke
Copy link
Author

pke commented Mar 6, 2017

Thanks for the efforts. Hadn't had time to check myself in a profiler yet. But lookup is always good.
Probably changing the regex to match "24/7" early on might also improve perf, depending on the scenario.

@ypid
Copy link
Member

ypid commented Mar 6, 2017

Probably changing the regex to match "24/7" early on might also improve perf

Should already be pretty early or do you see further room for improvement?

@pke
Copy link
Author

pke commented Mar 13, 2017

I wonder why the parser includes this awful regex
https://github.com/opening-hours/opening_hours.js/blob/master/index.js#L593

Is it really part of the spec that the opening hours string can be localized?
If not, I'd opt to remove that and simplify the regex.

@pke
Copy link
Author

pke commented Mar 13, 2017

re the "24/7". It's not the first one. Its inside the while loop after tmp = value.match(/^([a-z]{2,})\b((?:[.]| before| after)?)/i); even.
What circumstance would be a valid input value where "24/7" is only a part of and not the complete input? Like how likely is it that before and after "24/7" comes another valid token? Can there be a fallback token?

@ypid
Copy link
Member

ypid commented Mar 13, 2017

What circumstance would be a valid input value where "24/7" is only a part of and not the complete input?

It is illogical to do this but that does not keep people from doing just that (search for 24/7) and the spec disallow this. That is why the lib gives a warning in those cases.

Can there be a fallback token?

Mean a fallback rule? Sure, why not. This would even be allowed by the spec but it is illogical as well (which is why the lib gives a warning here as well).

Is it really part of the spec that the opening hours string can be localized?

No and never will be. This is part of the error tolerance. The reason it is in the core is historical. The lib cares for OSM first of all. Please refer to #143

@pke pke closed this as completed Dec 7, 2019
@ypid
Copy link
Member

ypid commented Dec 8, 2019

@pke Just because you don’t use this lib anymore does not mean that you have to close valid issues you reported ;-) Reopening.

For reference, you probably switched to https://github.com/pke/simple-opening-hours. I guess such info is always interesting for others reading this.

@ypid ypid reopened this Dec 8, 2019
@ypid ypid added the status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation. label Jan 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation. type: feature Introduction of new functionality.
Projects
None yet
Development

No branches or pull requests

2 participants