Ernie Rael wrote:
> >> With my corrected code, has profiling() still looks like ~11% of the the
> >> time (it's got those two vim_regexec...()); wonder if has_profiling()
> >> could/should cache the results of debuggy_find().
> > Caching can be tricky. In this case it can be difficult to clear cached
> > information when anything changes (new function defined, profiling entry
> > added/deleted, etc.).
>
> We're caching the result of running regexp on a name (I think); I don't see
> how adding a function changes that. I'm thinking of something like
>
> has_profiling(...)
> {
> result = table->get(fname, null);
> if (result == null)
> {
> result = debuggy_find(...);
> table[fname] = result;
> }
> return result; // handle direct return and optional forceit
> }
>
> The table is cleared whenever prof_ga is modified. Should be easy to
> detect since prof_ga is static in debugger.c.
>
> I was thinking of two tables, for file and function, and avoid constructing
> keys that distinguish the cases.
Keep in mind that for debugging the line number also matters. It would
be simpler to only do this for profiling, since for debugging the
performance isn't all that important.
> A potential problem is "forceit", I'm not sure what this is about and
> whether or not it can be cached. If it can be cached, the a value in the
> table is two bits, has_profile and forceit (assuming foreit is boolean).
"When the [!] is added then all functions defined in the script will
also be profiled."
This is handled in prof_def_func(). This doesn't involve any regexp,
thus it would be OK not to cache this.
> I'm also assuming that the main if condition is always true for
> has_profile; "bp->dbg_type == DBG_EXPR" is never true.
Right.
> Any simple examples of using hashtable in "C" that I can reference?
It's all in hashtab.c. E.g. hash_init(), hash_add() and hash_find().
Perhaps the use of b_keywtab can function as an example.
You might want to store the hash number with the function to avoid the
overhead of computing it. The overhead of looking up the key in the
table can't be avoided. Also, when more function names are being cached
updating the hash table can also take a noticable amount of time.
> > is it worth it?
>
> Some uniform degradation, while undesirable, is not unexpected when
> profiling. The problem here is the degradation in results is not uniform
> and is large in some cases; it is due to the regex engine and the order of
> stuff in a table that's used by the profiler. Can vary while running.
If the number of items in "prof_ga" grows then the overhead indeed
rapidly grows, since it goes over the list quite a few times.
Note that with caching the overhead can still be noticable, especially
when adding/removing items from "prof_ga".
> In this case, `map(in, Map1)`, the map builtin invokes a user defined
> function; I'm guessing on invocation of that function the profiler looks it
> up. The lookup takes a seemingly arbitrary amount of time and counts it
> against the `map`. I've seen results 50x slower for the `map`; while lines
> that do not involve a user function are not affected.
Yes, that can give misleading profiling results.
--
Not too long ago, unzipping in public was illegal...