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

Regular Expression Optimization for Phalcon\Mvc\Router #977

Merged
merged 7 commits into from Aug 2, 2013
Merged

Regular Expression Optimization for Phalcon\Mvc\Router #977

merged 7 commits into from Aug 2, 2013

Conversation

ghost
Copy link

@ghost ghost commented Aug 2, 2013

This patch mainly adds possessive quantifiers to the patterns generated by Phalcon\Mvc\Route and Phalcon\Mvc\Router\Route

Match /this-will-not-match!/ against #^/([a-zA-Z0-9_-]++)/?+# will be almost two times faster than match against #^/([a-zA-Z0-9_-]+)/?$# or #^/([a-zA-Z0-9_-]+)[/]{0,1}$#.

@ghost
Copy link
Author

ghost commented Aug 2, 2013

3ff9de2 adds phalcon_fetch_property_this() and phalcon_fetch_property_this_quick() functions.

Their main difference from phalcon_read_property_this() and phalcon_read_property_this_quick() is that they behave much like zend_read_property(): they do not copy property value not mess with reference counting — they just return the stored value as is.

The advantage of these functions is that their result does not need to be observed with PHALCON_OBS_VAR(). This is the ideal solution for scenarios like:

tmp = phalcon_fetch_property_this(this_ptr, SL("_defaultNamespace"), PH_NOISY_CC);
phalcon_update_property_this(this_ptr, SL("_namespace"), *tmp TSRMLS_CC);

This may save several variables and memory allocations.

RouterMvcTest run under callgrind before and after this change (a9c59c4):

Before:

  • inclusive cost: 3.64%
  • self cost: 2.93%

After:

  • inclusive cost: 3.56%
  • self cost: 2.91%

Not bad for the function invoked only 42 times.

@ghost
Copy link
Author

ghost commented Aug 2, 2013

460be93 adds phalcon_array_isset_fetch functions which combine isset and fetch functionality: these functions are two times faster than isset() + fetch() alone because even though isset() finds the item, fetch() has to look for it again.

3720315 applies this optimization to Router and wins another 0.02% of both inclusive and self cost.

phalcon pushed a commit that referenced this pull request Aug 2, 2013
Regular Expression Optimization for Phalcon\Mvc\Router
@phalcon phalcon merged commit 8e522e3 into phalcon:1.3.0 Aug 2, 2013
@phalcon
Copy link
Collaborator

phalcon commented Aug 2, 2013

Amazing, great!

@ghost ghost deleted the regexps branch August 2, 2013 15:15
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.

None yet

2 participants