libera/#commonlisp - IRC Chatlog
Search
23:16:37
sveit_
Hi. I saw a statement that "displaced arrays perform poorly" here: https://stackoverflow.com/questions/40810796/displaced-multidimensional-arrays-in-common-lisp#comment68846900_40810796 . Is someone here familiar with why this would be true?
23:17:30
sveit_
The reason I ask is that it is of course fairly simple to just implement an additional object that can store information on the "view" I'd like to provide on a flat array (as suggested in that comment) but why would my user-space implementation be better than what is in the compiler?
23:18:30
sveit_
(in case it's not claer, that link is directly to the comment by someone named Dan Robertson that has the statement i'm confused about)
23:19:15
Bike
so the problem is, say we have (aref a ...) in the code. if the compiler knows a is NOT displaced, that's pretty straightforward - bounds check and a memory read
23:19:36
Bike
but if it could be displaced, it has to compile in a check for that, and then code to loop through displacements to get the underlying array
23:20:01
Bike
with what the comment describes, you'd have one simple vector which can be accessed quickly, and then you just briefly compute the index you actually want
23:21:03
sveit_
Bike: i think you have revealed that I don't understand what array displacement means :) I thought it was exactly what you described in your last statement: a backing vector and some new procedure for computing indices
23:22:52
sveit_
Bike: sure, but doesn't the procedure "close" on itself? meaning if A0 is the original array, A1 is displaced to A0, and A2 is displaced to A1, can't the implementation just treat A2 as displaced to A0?
23:23:43
Bike
and, for example, if A1 is adjusted, A2 needs to reflect that adjustment, even if A0 itself has not changed
23:27:10
Bike
think the standards committee should have put a little more thought into this thing, honestly
23:30:22
Catie
Adjusting a displaced array is something they actually put a decent bit of thought into, there's an issue writeup about it
23:34:36
Bike
no, i mean instead of having displaced arrays like they exist, having a more limited construct that can't get recursive
23:47:35
aeth
there's no incentive to optimize displaced arrays because nobody uses displaced arrays... because they're not optimized
23:48:10
aeth
the idiomatic way of thinking is start/end indices and almost everything in the standard library has it, as well as any well-written third-party library
23:55:02
Bike
given that, in general, you have this indefinite-length chain of displacements to navigate
23:56:13
aeth
if the problem is the function ARRAY-DISPLACEMENT, and someone really wanted to optimize displaced arrays, couldn't they just optimize them if ARRAY-DISPLACEMENT cannot possibly show up in the program?
23:57:53
_death
Bike: what about keeping both the immediate displacement and the farthest one possible, and recomputing the latter when needed
23:58:13
Bike
yeah i guess you could have each array maintain weak backpointers to every array that's displaced to it
0:01:11
Bike
aeth: and for the record, it's more or less impossible (in general, actually impossible, for computability reasons) for a compiler to determine that some function will never be called, in a world where any function could be redefined to do (eval (read))
0:02:41
aeth
Bike: you do something like what JITs do... you are prepared to deoptimize if necessary. Easier task than JITs because you'd only need to do it on the equivalent of C-c C-c or C-c C-k
0:49:52
nij-
Hello! Is it possible to define setf-expander that does file reading and writing on the file?: https://bpa.st/LMUA
1:54:42
nij-
I might try another way. Instead of defsetf, is there a way to monitor the value cell of a symbol, so that whenever the value cell is changed, we invoke a certain function?
1:58:52
Catie
You could define a :before method on the (setf ...) function, but that only handles the case where it's mutated via setf
2:00:09
moon-child
(define-symbol-macro x '(get-x)) (let (x) (defun (get-x) x) (defun (setf get-x) (nx) (notify-about nx)))
2:09:19
nij-
moon-child: Oh I see I think you mean: (let (x) (defun get-x () x) (defun (setf get-x) (nx) (setf x nx)))
2:11:08
moon-child
tired, and I was thinking about wrapping the parentheses around (setf get-x), my fingers got ahead of me
9:35:35
nij-
Those who have used accesses - while it is great to access a place given by a variable, it doesn't seem to be working for a general place form like this
9:36:51
nij-
If I want to extend the behavior, I need to hack the function accesses to expand the inner forms, right? Is it possible in principle?
9:43:59
nij-
Ok.. without stupid mistake (hopefully), here's a case that's expected to work but not:
9:56:52
phoe
first, (setf (access:accesses (nth 0 *X*) '(:a :type :plist)) nil) because it is 1 at the moment
9:57:10
phoe
then, (setf (access:accesses (nth 0 *X*) '(:a :type :plist) '(:b :type :plist)) 10) to push into the new plist
9:59:49
phoe
either that, or implement type errors in access itself - it should tell you that it cannot treat 1 as a plist