-
Notifications
You must be signed in to change notification settings - Fork 133
Cache function eval result per argument set #988
Conversation
private readonly Dictionary<int, IMember> _argEvalCache = new Dictionary<int, IMember>(); | ||
|
||
private IMember TryEvaluateWithArguments(IPythonFunctionType fn, IArgumentSet args) { | ||
var name = fn.DeclaringType != null ? $"{fn.DeclaringModule.Name}.{fn.Name}" : fn.Name; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be affected by #979 where the DeclaringModule of a function I had was null
, so all functions of that style with the same name would get cached together.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but it is a bug. I'll work on it right after this. All types should have declaring module, there are many many places where we would crash otherwise.
var key = fn.DeclaringModule.Name.GetHashCode() ^ name.GetHashCode() ^ (397 * argHash); | ||
|
||
if (_argEvalCache.TryGetValue(key, out var result)) { | ||
return result; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't hash collisions here make some unrelated functions have the same evaluation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Functions have fully qualified names like module.class.method which should have unique hashes
* Fix microsoft#668 (partial) * Tests * Revert "Tests" This reverts commit 7ffc9db. * Exp * Limit concurrency * Concurrency limit * Drop cache after analysis * Fix regression * Fix test * Cache argument eval * Fix hash calculation * Fix exception when there is a space before triple quote * Fix exception
Performance