Skip to content

Commit

Permalink
Merge pull request #1825 from sjinks/persistent-fcall-cache
Browse files Browse the repository at this point in the history
Persistent fcall cache
  • Loading branch information
Phalcon committed Jan 15, 2014
2 parents 56a9b13 + e675786 commit d5dbce2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 50 deletions.
58 changes: 19 additions & 39 deletions ext/kernel/alternative/fcall.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ int phalcon_alt_call_method(zend_fcall_info *fci, zend_class_entry *ce, unsigned
EX(object) = NULL;

/* Check if a fci_cache is already loaded for this method */
if (hash_key > 0 && phalcon_globals_ptr->function_cache) {
if (hash_key > 0) {
if (zend_hash_index_find(phalcon_globals_ptr->function_cache, hash_key, (void**) &function_handler) == SUCCESS) {
fci_cache->function_handler = *function_handler;
exists = 1;
Expand Down Expand Up @@ -267,22 +267,14 @@ int phalcon_alt_call_method(zend_fcall_info *fci, zend_class_entry *ce, unsigned
}

/* Store the function in the cache only if it is a zend internal function */
if (is_phalcon_function) {
if (fci_cache->function_handler->type == ZEND_INTERNAL_FUNCTION) {

if (!phalcon_globals_ptr->function_cache) {
ALLOC_HASHTABLE(phalcon_globals_ptr->function_cache);
zend_hash_init(phalcon_globals_ptr->function_cache, 0, NULL, NULL, 0);
}

zend_hash_index_update(
phalcon_globals_ptr->function_cache,
hash_key,
&fci_cache->function_handler,
sizeof(zend_function *),
NULL
);
}
if (is_phalcon_function && fci_cache->function_handler->type == ZEND_INTERNAL_FUNCTION) {
zend_hash_index_update(
phalcon_globals_ptr->function_cache,
hash_key,
&fci_cache->function_handler,
sizeof(zend_function *),
NULL
);
}

} else {
Expand Down Expand Up @@ -557,7 +549,7 @@ int phalcon_alt_call_method(zend_fcall_info *fci, zend_class_entry *ce, unsigned
EX(object) = NULL;

/* Check if a fci_cache is already loaded for this method */
if (hash_key > 0 && phalcon_globals_ptr->function_cache) {
if (hash_key > 0) {
if (zend_hash_index_find(phalcon_globals_ptr->function_cache, hash_key, (void**) &function_handler) == SUCCESS) {
fci_cache->function_handler = *function_handler;
exists = 1;
Expand All @@ -567,11 +559,7 @@ int phalcon_alt_call_method(zend_fcall_info *fci, zend_class_entry *ce, unsigned

/** Check if it's a Phalcon function */
if (!is_phalcon_function) {
if (ce->type == ZEND_INTERNAL_CLASS) {
if (ce->name_length > 10) {
is_phalcon_function = !memcmp(ce->name, SL("Phalcon\\"));
}
}
is_phalcon_function = is_phalcon_class(ce);
}

/* The fci_cache doesn't exist, so we check it */
Expand Down Expand Up @@ -620,22 +608,14 @@ int phalcon_alt_call_method(zend_fcall_info *fci, zend_class_entry *ce, unsigned
}

/* Store the function in the cache only if it is a zend internal function */
if (is_phalcon_function) {
if (likely(fci_cache->function_handler->type == ZEND_INTERNAL_FUNCTION)) {

if (!phalcon_globals_ptr->function_cache) {
ALLOC_HASHTABLE(phalcon_globals_ptr->function_cache);
zend_hash_init(phalcon_globals_ptr->function_cache, 0, NULL, NULL, 0);
}

zend_hash_index_update(
phalcon_globals_ptr->function_cache,
hash_key,
&fci_cache->function_handler,
sizeof(zend_function *),
NULL
);
}
if (is_phalcon_function && likely(fci_cache->function_handler->type == ZEND_INTERNAL_FUNCTION)) {
zend_hash_index_update(
phalcon_globals_ptr->function_cache,
hash_key,
&fci_cache->function_handler,
sizeof(zend_function *),
NULL
);
}

} else {
Expand Down
4 changes: 0 additions & 4 deletions ext/kernel/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ void php_phalcon_init_globals(zend_phalcon_globals *phalcon_globals TSRMLS_DC) {
/* Virtual Symbol Tables */
phalcon_globals->active_symbol_table = NULL;

/* Cache options */
phalcon_globals->function_cache = NULL;

/* Recursive Lock */
phalcon_globals->recursive_lock = 0;

Expand All @@ -60,7 +57,6 @@ void php_phalcon_init_globals(zend_phalcon_globals *phalcon_globals TSRMLS_DC) {

/* DB options */
phalcon_globals->db.escape_identifiers = 1;

}

/**
Expand Down
14 changes: 7 additions & 7 deletions ext/phalcon.c
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,6 @@ static PHP_MINIT_FUNCTION(phalcon){

static PHP_MSHUTDOWN_FUNCTION(phalcon){

assert(PHALCON_GLOBAL(function_cache) == NULL);
assert(PHALCON_GLOBAL(orm).parser_cache == NULL);
assert(PHALCON_GLOBAL(orm).ast_cache == NULL);

Expand All @@ -548,12 +547,6 @@ static PHP_RSHUTDOWN_FUNCTION(phalcon){
phalcon_clean_restore_stack(TSRMLS_C);
}

if (PHALCON_GLOBAL(function_cache) != NULL) {
zend_hash_destroy(PHALCON_GLOBAL(function_cache));
FREE_HASHTABLE(PHALCON_GLOBAL(function_cache));
PHALCON_GLOBAL(function_cache) = NULL;
}

phalcon_orm_destroy_cache(TSRMLS_C);

#ifndef PHALCON_RELEASE
Expand Down Expand Up @@ -593,6 +586,9 @@ static PHP_GINIT_FUNCTION(phalcon)

phalcon_globals->start_memory = start;

phalcon_globals->function_cache = pemalloc(sizeof(HashTable), 1);
zend_hash_init(phalcon_globals->function_cache, 128, NULL, NULL, 1);

/* 'Allocator sizeof operand mismatch' warning can be safely ignored */
ALLOC_PERMANENT_ZVAL(phalcon_globals->z_null);
INIT_ZVAL(*phalcon_globals->z_null);
Expand Down Expand Up @@ -632,6 +628,10 @@ static PHP_GSHUTDOWN_FUNCTION(phalcon)
pefree(phalcon_globals->start_memory, 1);
phalcon_globals->start_memory = NULL;

zend_hash_destroy(phalcon_globals->function_cache);
pefree(phalcon_globals->function_cache, 1);
phalcon_globals->function_cache = NULL;

#ifndef PHALCON_RELEASE
phalcon_verify_permanent_zvals(1 TSRMLS_CC);
#endif
Expand Down

0 comments on commit d5dbce2

Please sign in to comment.