-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove usages of environment-map #1350
Conversation
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.
My only thought would be to run some sort of benchmark to make sure this is comparable or faster.
Otherwise, looks good!
src/typechecker/environment.lisp
Outdated
@@ -1382,14 +1373,20 @@ | |||
entry) | |||
#'make-fundep-environment)))) | |||
|
|||
(defun class-variable-map (class) |
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.
Overall, I like the spirit of this PR, but when I compiled coalton
and coalton/test
with the following extra lines, there are cases where this function is run as many as 90 times on a single class. On the other hand, this function is, overall, not called that many times. I printed the results below.
(defvar *called-class-variable-map-p-table* (make-hash-table :test 'eq))
(defun class-variable-map (class)
(format t "Call number ~D on this class." (incf (gethash class *called-class-variable-map-p-table* 0)))
(loop :with table := (make-hash-table)
:for var :in (ty-class-class-variables class)
:for i :from 0
:do (setf (gethash var table) i)
:finally (return table)))
Running (asdf:load-system "coalton" :force t)
Called class-variable-map 171 times on TRYINTO
Called class-variable-map 6 times on RANDOMACCESS
Called class-variable-map 2 times on INTOITERATOR
Called class-variable-map 116 times on INTOITERATOR
Called class-variable-map 71 times on FROMITERATOR
Called class-variable-map 2 times on RANDOMACCESS
Called class-variable-map 94 times on ADD
Called class-variable-map 71 times on FIB
Called class-variable-map 2 times on ADD
Called class-variable-map 3 times on FIB
Called class-variable-map 2 times on C
Called class-variable-map 2 times on C
Called class-variable-map 2 times on C
Called class-variable-map 2 times on C
Called class-variable-map 2 times on C
Called class-variable-map 4 times on C
Called class-variable-map 3 times on MOO
Called class-variable-map 2 times on C
Called class-variable-map 2 times on C
Called class-variable-map 2 times on C
Called class-variable-map 84 times on TRYINTO
Called class-variable-map 69 times on INTOITERATOR
Called class-variable-map 46 times on FROMITERATOR
Called class-variable-map 1 times on RANDOMACCESS
Called class-variable-map 2 times on ADD
Called class-variable-map 3 times on FIB
Called class-variable-map 94 times on ADD
Called class-variable-map 71 times on FIB
Called class-variable-map 2 times on ADD
Called class-variable-map 3 times on FIB
Called class-variable-map 171 times on TRYINTO
Called class-variable-map 6 times on RANDOMACCESS
Called class-variable-map 2 times on INTOITERATOR
Called class-variable-map 110 times on INTOITERATOR
Called class-variable-map 68 times on FROMITERATOR
Called class-variable-map 2 times on RANDOMACCESS
Called class-variable-map 94 times on ADD
Called class-variable-map 71 times on FIB
Called class-variable-map 2 times on ADD
Called class-variable-map 3 times on FIB
Called class-variable-map 171 times on TRYINTO
Called class-variable-map 6 times on RANDOMACCESS
Called class-variable-map 2 times on INTOITERATOR
Called class-variable-map 110 times on INTOITERATOR
Called class-variable-map 68 times on FROMITERATOR
Called class-variable-map 2 times on RANDOMACCESS
Called class-variable-map 94 times on ADD
Called class-variable-map 71 times on FIB
Called class-variable-map 2 times on ADD
Called class-variable-map 3 times on FIB
Called class-variable-map 171 times on TRYINTO
Called class-variable-map 6 times on RANDOMACCESS
Called class-variable-map 2 times on INTOITERATOR
Called class-variable-map 54 times on INTOITERATOR
Called class-variable-map 33 times on FROMITERATOR
Called class-variable-map 2 times on RANDOMACCESS
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.
Other than this, I don't think I have any comments, I like +62 vs -208 LOC 😎
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.
And 9 of those are docstrings :)
Following up @Izaakwltn's suggestion to check benchmarking, repeated runs of the test suite don't flag obvious performance regressions. That's tempered by the knowledge that there's not good coverage for, e.g., superclasses. That Test
Main
environment-map
|
I'll take a look. |
d271586
to
3e4680b
Compare
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.
Sorry for the delay on this. I have one very modest request which is to be very explicit on what a data type is.
(fundeps (util:required 'fundeps) :type fundep-list :read-only t) | ||
|
||
;; Methods of the class containing the same tyvars in PREDICATE for | ||
;; use in pretty printing | ||
(unqualified-methods (util:required 'unqualified-methods) :type ty-class-method-list :read-only t) | ||
(codegen-sym (util:required 'codegen-sym) :type symbol :read-only t) | ||
(superclass-dict (util:required 'superclass-dict) :type list :read-only t) | ||
(superclass-map (util:required 'superclass-map) :type environment-map :read-only t) | ||
(superclass-map (util:required 'superclass-map) :type list :read-only t) |
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.
Can you write a comment describing the keys and values here? I don't think "list" is self-evident. Something like
;; an immutable alist of the form ((a1 b1) ...) whose keys are ... and values are ...
clarify if it's an alist of lists or an alist of conses.
I would say this is the sole and biggest negative of this change, we are using an ad hoc data structure.
Environment maps were introduced in order to provide platform-agnostic dumping of hashtables present in Coalton environment structures. A review of the three locations where these maps are present (method-codegen-sym, class-variable-map, superclass-map) indicates that in all cases, a simple list or alist structure is more appropriate because of the small number of elements consulted. In particular, method-codegen-syms are 1-1 with the method-names list, so no mapping is needed.
3e4680b
to
feb8f3e
Compare
Environment maps were introduced in order to provide platform-agnostic
dumping of hashtables present in Coalton environment structures.
A review of the three locations where these maps are
present (method-codegen-sym, class-variable-map, superclass-map)
indicates that in all cases, a simple list or alist structure is more
appropriate because of the small number of elements consulted.
In particular, method-codegen-syms are 1-1 with the method-names list,
so no mapping is needed at all.