tried performance optimization

This commit is contained in:
hyung-hwan 2008-01-16 03:01:47 +00:00
parent 4ae1cec546
commit 57fec6392e
3 changed files with 83 additions and 10 deletions

View File

@ -244,12 +244,16 @@ struct ase_awk_run_t
ase_size_t stack_limit; ase_size_t stack_limit;
int exit_level; int exit_level;
ase_awk_val_int_t* icache[200]; /* TODO: choose the optimal size */ ase_awk_val_int_t* icache[128];
ase_awk_val_real_t* rcache[200]; /* TODO: choose the optimal size */ ase_awk_val_real_t* rcache[128];
ase_awk_val_ref_t* fcache[200]; /* TODO: choose the optimal size */ ase_awk_val_ref_t* fcache[128];
ase_awk_val_str_t* scache32[128];
ase_awk_val_str_t* scache64[128];
ase_size_t icache_count; ase_size_t icache_count;
ase_size_t rcache_count; ase_size_t rcache_count;
ase_size_t fcache_count; ase_size_t fcache_count;
ase_size_t scache32_count;
ase_size_t scache64_count;
ase_awk_nde_blk_t* active_block; ase_awk_nde_blk_t* active_block;
ase_byte_t* pattern_range_state; ase_byte_t* pattern_range_state;

View File

@ -745,6 +745,8 @@ static int init_run (
run->icache_count = 0; run->icache_count = 0;
run->rcache_count = 0; run->rcache_count = 0;
run->fcache_count = 0; run->fcache_count = 0;
run->scache32_count = 0;
run->scache64_count = 0;
run->errnum = ASE_AWK_ENOERR; run->errnum = ASE_AWK_ENOERR;
run->errlin = 0; run->errlin = 0;
@ -962,6 +964,18 @@ static void deinit_run (ase_awk_run_t* run)
ase_awk_val_ref_t* tmp = run->fcache[--run->fcache_count]; ase_awk_val_ref_t* tmp = run->fcache[--run->fcache_count];
ase_awk_freeval (run, (ase_awk_val_t*)tmp, ase_false); ase_awk_freeval (run, (ase_awk_val_t*)tmp, ase_false);
} }
while (run->scache32_count > 0)
{
ase_awk_val_str_t* tmp = run->scache32[--run->scache32_count];
ase_awk_freeval (run, (ase_awk_val_t*)tmp, ase_false);
}
while (run->scache64_count > 0)
{
ase_awk_val_str_t* tmp = run->scache64[--run->scache64_count];
ase_awk_freeval (run, (ase_awk_val_t*)tmp, ase_false);
}
} }
static int build_runarg ( static int build_runarg (

View File

@ -133,17 +133,38 @@ ase_awk_val_t* ase_awk_makestrval (
ase_awk_run_t* run, const ase_char_t* str, ase_size_t len) ase_awk_run_t* run, const ase_char_t* str, ase_size_t len)
{ {
ase_awk_val_str_t* val; ase_awk_val_str_t* val;
ase_size_t rlen = len;
if (rlen <= 32)
{
if (run->scache32_count > 0)
{
val = run->scache32[--run->scache32_count];
goto init;
}
rlen = 32;
}
else if (rlen <= 64)
{
if (run->scache64_count > 0)
{
val = run->scache64[--run->scache64_count];
goto init;
}
rlen = 64;
}
val = (ase_awk_val_str_t*) ASE_AWK_MALLOC ( val = (ase_awk_val_str_t*) ASE_AWK_MALLOC (
run->awk, run->awk,
ASE_SIZEOF(ase_awk_val_str_t) + ASE_SIZEOF(ase_awk_val_str_t) +
(len+1)*ASE_SIZEOF(ase_char_t)); (rlen+1)*ASE_SIZEOF(ase_char_t));
if (val == ASE_NULL) if (val == ASE_NULL)
{ {
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM); ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
return ASE_NULL; return ASE_NULL;
} }
init:
val->type = ASE_AWK_VAL_STR; val->type = ASE_AWK_VAL_STR;
val->ref = 0; val->ref = 0;
val->len = len; val->len = len;
@ -183,17 +204,38 @@ ase_awk_val_t* ase_awk_makestrval2 (
const ase_char_t* str2, ase_size_t len2) const ase_char_t* str2, ase_size_t len2)
{ {
ase_awk_val_str_t* val; ase_awk_val_str_t* val;
ase_size_t rlen = len1 + len2;
if (rlen <= 32)
{
if (run->scache32_count > 0)
{
val = run->scache32[--run->scache32_count];
goto init;
}
rlen = 32;
}
else if (rlen <= 64)
{
if (run->scache64_count > 0)
{
val = run->scache64[--run->scache64_count];
goto init;
}
rlen = 64;
}
val = (ase_awk_val_str_t*) ASE_AWK_MALLOC ( val = (ase_awk_val_str_t*) ASE_AWK_MALLOC (
run->awk, run->awk,
ASE_SIZEOF(ase_awk_val_str_t) + ASE_SIZEOF(ase_awk_val_str_t) +
(len1+len2+1)*ASE_SIZEOF(ase_char_t)); (rlen+1)*ASE_SIZEOF(ase_char_t));
if (val == ASE_NULL) if (val == ASE_NULL)
{ {
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM); ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
return ASE_NULL; return ASE_NULL;
} }
init:
val->type = ASE_AWK_VAL_STR; val->type = ASE_AWK_VAL_STR;
val->ref = 0; val->ref = 0;
val->len = len1 + len2; val->len = len1 + len2;
@ -343,8 +385,7 @@ void ase_awk_freeval (ase_awk_run_t* run, ase_awk_val_t* val, ase_bool_t cache)
} }
else if (val->type == ASE_AWK_VAL_INT) else if (val->type == ASE_AWK_VAL_INT)
{ {
if (cache == ase_true && if (cache && run->icache_count < ASE_COUNTOF(run->icache))
run->icache_count < ASE_COUNTOF(run->icache))
{ {
run->icache[run->icache_count++] = run->icache[run->icache_count++] =
(ase_awk_val_int_t*)val; (ase_awk_val_int_t*)val;
@ -353,8 +394,7 @@ void ase_awk_freeval (ase_awk_run_t* run, ase_awk_val_t* val, ase_bool_t cache)
} }
else if (val->type == ASE_AWK_VAL_REAL) else if (val->type == ASE_AWK_VAL_REAL)
{ {
if (cache == ase_true && if (cache && run->rcache_count < ASE_COUNTOF(run->rcache))
run->rcache_count < ASE_COUNTOF(run->rcache))
{ {
run->rcache[run->rcache_count++] = run->rcache[run->rcache_count++] =
(ase_awk_val_real_t*)val; (ase_awk_val_real_t*)val;
@ -364,7 +404,22 @@ void ase_awk_freeval (ase_awk_run_t* run, ase_awk_val_t* val, ase_bool_t cache)
else if (val->type == ASE_AWK_VAL_STR) else if (val->type == ASE_AWK_VAL_STR)
{ {
/*ASE_AWK_FREE (run->awk, ((ase_awk_val_str_t*)val)->buf);*/ /*ASE_AWK_FREE (run->awk, ((ase_awk_val_str_t*)val)->buf);*/
ASE_AWK_FREE (run->awk, val); if (cache)
{
ase_awk_val_str_t* v = (ase_awk_val_str_t*)val;
if (v->len <= 32 &&
run->scache32_count<ASE_COUNTOF(run->scache32))
{
run->scache32[run->scache32_count++] = v;
}
else if (v->len <= 64 &&
run->scache64_count<ASE_COUNTOF(run->scache64))
{
run->scache64[run->scache64_count++] = v;
}
else ASE_AWK_FREE (run->awk, val);
}
else ASE_AWK_FREE (run->awk, val);
} }
else if (val->type == ASE_AWK_VAL_REX) else if (val->type == ASE_AWK_VAL_REX)
{ {