Speed up unserialize() and fix a serious performance issue.

Obtained from:	PHP CVS
This commit is contained in:
Alex Dupre 2005-01-19 16:13:55 +00:00
parent 49863871d1
commit 114b2bec5b
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=126843
9 changed files with 324 additions and 3 deletions

View file

@ -7,7 +7,7 @@
PORTNAME= php4
PORTVERSION= 4.3.10
PORTREVISION?= 1
PORTREVISION?= 2
CATEGORIES?= lang devel www
MASTER_SITES= ${MASTER_SITE_PHP:S,$,:release,} \
http://downloads.php.net/ilia/:rc \

View file

@ -0,0 +1,20 @@
--- ext/standard/php_var.h.orig 2004/09/05 16:29:04
+++ ext/standard/php_var.h 2005/01/15 18:18:08
@@ -41,6 +41,7 @@ PHPAPI void php_debug_zval_dump(zval **s
struct php_unserialize_data {
void *first;
+ void *first_dtor;
};
typedef struct php_unserialize_data php_unserialize_data_t;
@@ -54,7 +55,8 @@ PHPAPI int php_var_unserialize(zval **rv
zend_hash_destroy(&(var_hash))
#define PHP_VAR_UNSERIALIZE_INIT(var_hash) \
- (var_hash).first = 0
+ (var_hash).first = 0; \
+ (var_hash).first_dtor = 0
#define PHP_VAR_UNSERIALIZE_DESTROY(var_hash) \
var_destroy(&(var_hash))

View file

@ -0,0 +1,87 @@
--- ext/standard/var_unserializer.c.orig 2004/12/03 16:02:48
+++ ext/standard/var_unserializer.c 2005/01/18 10:57:05
@@ -56,6 +56,30 @@ static inline void var_push(php_unserial
var_hash->data[var_hash->used_slots++] = *rval;
}
+static inline void var_push_dtor(php_unserialize_data_t *var_hashx, zval **rval)
+{
+ var_entries *var_hash = var_hashx->first_dtor, *prev = NULL;
+
+ while (var_hash && var_hash->used_slots == VAR_ENTRIES_MAX) {
+ prev = var_hash;
+ var_hash = var_hash->next;
+ }
+
+ if (!var_hash) {
+ var_hash = emalloc(sizeof(var_entries));
+ var_hash->used_slots = 0;
+ var_hash->next = 0;
+
+ if (!var_hashx->first_dtor)
+ var_hashx->first_dtor = var_hash;
+ else
+ prev->next = var_hash;
+ }
+
+ (*rval)->refcount++;
+ var_hash->data[var_hash->used_slots++] = *rval;
+}
+
PHPAPI void var_replace(php_unserialize_data_t *var_hashx, zval *ozval, zval **nzval)
{
int i;
@@ -93,6 +117,7 @@ static int var_access(php_unserialize_da
PHPAPI void var_destroy(php_unserialize_data_t *var_hashx)
{
void *next;
+ int i;
var_entries *var_hash = var_hashx->first;
while (var_hash) {
@@ -100,6 +125,17 @@ PHPAPI void var_destroy(php_unserialize_
efree(var_hash);
var_hash = next;
}
+
+ var_hash = var_hashx->first_dtor;
+
+ while (var_hash) {
+ for (i = 0; i < var_hash->used_slots; i++) {
+ zval_ptr_dtor(&var_hash->data[i]);
+ }
+ next = var_hash->next;
+ efree(var_hash);
+ var_hash = next;
+ }
}
/* }}} */
@@ -177,7 +213,7 @@ static inline size_t parse_uiv(const uns
static inline int process_nested_data(UNSERIALIZE_PARAMETER, HashTable *ht, int elements)
{
while (elements-- > 0) {
- zval *key, *data, *old_data;
+ zval *key, *data, **old_data;
ALLOC_INIT_ZVAL(key);
@@ -205,14 +241,14 @@ static inline int process_nested_data(UN
switch (Z_TYPE_P(key)) {
case IS_LONG:
- if (zend_hash_index_find(ht, Z_LVAL_P(key), (void **)&old_data)) {
- var_replace(var_hash, old_data, rval);
+ if (zend_hash_index_find(ht, Z_LVAL_P(key), (void **)&old_data)==SUCCESS) {
+ var_push_dtor(var_hash, old_data);
}
zend_hash_index_update(ht, Z_LVAL_P(key), &data, sizeof(data), NULL);
break;
case IS_STRING:
- if (zend_hash_find(ht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, (void **)&old_data)) {
- var_replace(var_hash, old_data, rval);
+ if (zend_hash_find(ht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, (void **)&old_data)==SUCCESS) {
+ var_push_dtor(var_hash, old_data);
}
zend_hash_update(ht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, &data, sizeof(data), NULL);
break;

View file

@ -7,7 +7,7 @@
PORTNAME= php5
PORTVERSION= 5.0.3
PORTREVISION?= 1
PORTREVISION?= 2
CATEGORIES?= lang devel www
MASTER_SITES= ${MASTER_SITE_PHP:S,$,:release,} \
http://downloads.php.net/ilia/:rc \

View file

@ -0,0 +1,20 @@
--- ext/standard/php_var.h.orig 2004/09/05 16:29:04
+++ ext/standard/php_var.h 2005/01/15 18:18:08
@@ -41,6 +41,7 @@ PHPAPI void php_debug_zval_dump(zval **s
struct php_unserialize_data {
void *first;
+ void *first_dtor;
};
typedef struct php_unserialize_data php_unserialize_data_t;
@@ -54,7 +55,8 @@ PHPAPI int php_var_unserialize(zval **rv
zend_hash_destroy(&(var_hash))
#define PHP_VAR_UNSERIALIZE_INIT(var_hash) \
- (var_hash).first = 0
+ (var_hash).first = 0; \
+ (var_hash).first_dtor = 0
#define PHP_VAR_UNSERIALIZE_DESTROY(var_hash) \
var_destroy(&(var_hash))

View file

@ -0,0 +1,87 @@
--- ext/standard/var_unserializer.c.orig 2004/12/03 16:02:48
+++ ext/standard/var_unserializer.c 2005/01/18 10:57:05
@@ -56,6 +56,30 @@ static inline void var_push(php_unserial
var_hash->data[var_hash->used_slots++] = *rval;
}
+static inline void var_push_dtor(php_unserialize_data_t *var_hashx, zval **rval)
+{
+ var_entries *var_hash = var_hashx->first_dtor, *prev = NULL;
+
+ while (var_hash && var_hash->used_slots == VAR_ENTRIES_MAX) {
+ prev = var_hash;
+ var_hash = var_hash->next;
+ }
+
+ if (!var_hash) {
+ var_hash = emalloc(sizeof(var_entries));
+ var_hash->used_slots = 0;
+ var_hash->next = 0;
+
+ if (!var_hashx->first_dtor)
+ var_hashx->first_dtor = var_hash;
+ else
+ prev->next = var_hash;
+ }
+
+ (*rval)->refcount++;
+ var_hash->data[var_hash->used_slots++] = *rval;
+}
+
PHPAPI void var_replace(php_unserialize_data_t *var_hashx, zval *ozval, zval **nzval)
{
int i;
@@ -93,6 +117,7 @@ static int var_access(php_unserialize_da
PHPAPI void var_destroy(php_unserialize_data_t *var_hashx)
{
void *next;
+ int i;
var_entries *var_hash = var_hashx->first;
while (var_hash) {
@@ -100,6 +125,17 @@ PHPAPI void var_destroy(php_unserialize_
efree(var_hash);
var_hash = next;
}
+
+ var_hash = var_hashx->first_dtor;
+
+ while (var_hash) {
+ for (i = 0; i < var_hash->used_slots; i++) {
+ zval_ptr_dtor(&var_hash->data[i]);
+ }
+ next = var_hash->next;
+ efree(var_hash);
+ var_hash = next;
+ }
}
/* }}} */
@@ -177,7 +213,7 @@ static inline size_t parse_uiv(const uns
static inline int process_nested_data(UNSERIALIZE_PARAMETER, HashTable *ht, int elements)
{
while (elements-- > 0) {
- zval *key, *data, *old_data;
+ zval *key, *data, **old_data;
ALLOC_INIT_ZVAL(key);
@@ -205,14 +241,14 @@ static inline int process_nested_data(UN
switch (Z_TYPE_P(key)) {
case IS_LONG:
- if (zend_hash_index_find(ht, Z_LVAL_P(key), (void **)&old_data)) {
- var_replace(var_hash, old_data, rval);
+ if (zend_hash_index_find(ht, Z_LVAL_P(key), (void **)&old_data)==SUCCESS) {
+ var_push_dtor(var_hash, old_data);
}
zend_hash_index_update(ht, Z_LVAL_P(key), &data, sizeof(data), NULL);
break;
case IS_STRING:
- if (zend_hash_find(ht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, (void **)&old_data)) {
- var_replace(var_hash, old_data, rval);
+ if (zend_hash_find(ht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, (void **)&old_data)==SUCCESS) {
+ var_push_dtor(var_hash, old_data);
}
zend_hash_update(ht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, &data, sizeof(data), NULL);
break;

View file

@ -7,7 +7,7 @@
PORTNAME= php5
PORTVERSION= 5.0.3
PORTREVISION?= 1
PORTREVISION?= 2
CATEGORIES?= lang devel www
MASTER_SITES= ${MASTER_SITE_PHP:S,$,:release,} \
http://downloads.php.net/ilia/:rc \

View file

@ -0,0 +1,20 @@
--- ext/standard/php_var.h.orig 2004/09/05 16:29:04
+++ ext/standard/php_var.h 2005/01/15 18:18:08
@@ -41,6 +41,7 @@ PHPAPI void php_debug_zval_dump(zval **s
struct php_unserialize_data {
void *first;
+ void *first_dtor;
};
typedef struct php_unserialize_data php_unserialize_data_t;
@@ -54,7 +55,8 @@ PHPAPI int php_var_unserialize(zval **rv
zend_hash_destroy(&(var_hash))
#define PHP_VAR_UNSERIALIZE_INIT(var_hash) \
- (var_hash).first = 0
+ (var_hash).first = 0; \
+ (var_hash).first_dtor = 0
#define PHP_VAR_UNSERIALIZE_DESTROY(var_hash) \
var_destroy(&(var_hash))

View file

@ -0,0 +1,87 @@
--- ext/standard/var_unserializer.c.orig 2004/12/03 16:02:48
+++ ext/standard/var_unserializer.c 2005/01/18 10:57:05
@@ -56,6 +56,30 @@ static inline void var_push(php_unserial
var_hash->data[var_hash->used_slots++] = *rval;
}
+static inline void var_push_dtor(php_unserialize_data_t *var_hashx, zval **rval)
+{
+ var_entries *var_hash = var_hashx->first_dtor, *prev = NULL;
+
+ while (var_hash && var_hash->used_slots == VAR_ENTRIES_MAX) {
+ prev = var_hash;
+ var_hash = var_hash->next;
+ }
+
+ if (!var_hash) {
+ var_hash = emalloc(sizeof(var_entries));
+ var_hash->used_slots = 0;
+ var_hash->next = 0;
+
+ if (!var_hashx->first_dtor)
+ var_hashx->first_dtor = var_hash;
+ else
+ prev->next = var_hash;
+ }
+
+ (*rval)->refcount++;
+ var_hash->data[var_hash->used_slots++] = *rval;
+}
+
PHPAPI void var_replace(php_unserialize_data_t *var_hashx, zval *ozval, zval **nzval)
{
int i;
@@ -93,6 +117,7 @@ static int var_access(php_unserialize_da
PHPAPI void var_destroy(php_unserialize_data_t *var_hashx)
{
void *next;
+ int i;
var_entries *var_hash = var_hashx->first;
while (var_hash) {
@@ -100,6 +125,17 @@ PHPAPI void var_destroy(php_unserialize_
efree(var_hash);
var_hash = next;
}
+
+ var_hash = var_hashx->first_dtor;
+
+ while (var_hash) {
+ for (i = 0; i < var_hash->used_slots; i++) {
+ zval_ptr_dtor(&var_hash->data[i]);
+ }
+ next = var_hash->next;
+ efree(var_hash);
+ var_hash = next;
+ }
}
/* }}} */
@@ -177,7 +213,7 @@ static inline size_t parse_uiv(const uns
static inline int process_nested_data(UNSERIALIZE_PARAMETER, HashTable *ht, int elements)
{
while (elements-- > 0) {
- zval *key, *data, *old_data;
+ zval *key, *data, **old_data;
ALLOC_INIT_ZVAL(key);
@@ -205,14 +241,14 @@ static inline int process_nested_data(UN
switch (Z_TYPE_P(key)) {
case IS_LONG:
- if (zend_hash_index_find(ht, Z_LVAL_P(key), (void **)&old_data)) {
- var_replace(var_hash, old_data, rval);
+ if (zend_hash_index_find(ht, Z_LVAL_P(key), (void **)&old_data)==SUCCESS) {
+ var_push_dtor(var_hash, old_data);
}
zend_hash_index_update(ht, Z_LVAL_P(key), &data, sizeof(data), NULL);
break;
case IS_STRING:
- if (zend_hash_find(ht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, (void **)&old_data)) {
- var_replace(var_hash, old_data, rval);
+ if (zend_hash_find(ht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, (void **)&old_data)==SUCCESS) {
+ var_push_dtor(var_hash, old_data);
}
zend_hash_update(ht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, &data, sizeof(data), NULL);
break;