freenode/lisp - IRC Chatlog
Search
8:56:45
beach
no-defun-allowed: It may be a case that is similar to the comparison between PCL generic dispatch and SICL generic dispatch. PCL uses a table in memory and SICL uses binary search.
8:57:38
no-defun-allowed
Yes, I based the dispatch off SICL binary search (and we have discussed it before).
9:07:10
no-defun-allowed
You had suggested using a jump table yesterday, and I've been eager to test how SBCL handles those, but I haven't had very good results.
9:09:05
Josh_2
Morning all. Does anyone know how I can optimize these 3 functions https://plaster.tymoon.eu/view/1719#1719 anymore?
9:13:49
no-defun-allowed
And please don't use (safety 0) unless you are very certain that nothing can go wrong, and then only in small doses.
9:17:06
Josh_2
Besides, they are the backbone of the system, they need to be performant for the entire system to be performant
9:24:36
no-defun-allowed
It is usually unwise to use (safety 0) to disable runtime checks, because the problems that could arise if some invariants you decided on are broken would be more of a problem than the slight decrease in throughput caused by checks.
9:24:50
no-defun-allowed
As Baker bluntly put it (in the case of some embedded systems), "rather than having the software discover its own errors in a benign way, the discovery of such errors is left to the FAA or a Congressional committee."
9:26:51
no-defun-allowed
Looking at line 6, (THE BOOLEAN (LISTEN STREAM)) might be incorrect, because LISTEN only returns a generalised boolean. It is also excessive, because comparing an object to NIL is no faster if you know what the object could otherwise be.
9:28:36
no-defun-allowed
I think READ-N-BYTES would be better written as a wrapper over READ-SEQUENCE, but it may be that spelling out the definition gives better type inference in your case.
10:29:19
no-defun-allowed
Some implementations may type check at THE, some may assume the value will always be of the provided type.
10:30:46
no-defun-allowed
But profile your code, please. I would recommend SB-SPROF if you're on SBCL to get some prerequisite information.
10:34:20
heisig
There are also several tools for visualizing SBCL's profiler output, like clim.flamegraph and cl-flamegraph.
10:35:29
no-defun-allowed
Absolutely, then you should move to the non-statistical profiler, which records calls and provides more precise information.
10:36:19
no-defun-allowed
But the statistical profiler just checks a thread's call stack frequently, instead of wrapping functions from a set you choose, which I think is better for getting an idea of where cycles are burnt.
10:44:55
flip214
> SBCL includes both a deterministic profiler, that can collect statistics on individual functions, and a more “modern” statistical profiler.
13:51:21
jdz
Bike: Just look at the list of people in this channel, and how many of them you know have typed anything?
13:59:26
flip214
Bike: if there are no members, just assert yourself as the first one -- and declare independence!
14:00:51
phoe
flip214: I don't know if the platinum sponsors club can survive an infinite increase in its member ratio
15:42:19
_Ark_
Does anyone know a way to get a nanosecond/cpu timestamp in Common Lisp (or at least sbcl)? I'm looking for something like Java's `nanoTime` https://docs.oracle.com/javase/7/docs/api/java/lang/System.html#nanoTime()
15:42:25
_Ark_
I've tried `(get-internal-run-time)` along with `internal-time-units-per-second`, but on SBCL it gives milliseconds.
15:44:47
Xach
_Ark_: i don't know if there's a more direct way, but you could use sb-alien to use the underlying OS apis. if you know what OS api provides it, you could also grep SBCL sources for something that uses that API.
15:46:24
pjb
or (com.informatimago.common-lisp.cesarum.time:get-real-time) #| --> 3.794139978273096D+9 |#
15:46:39
pjb
or (com.informatimago.common-lisp.cesarum.time:get-run-time) #| --> 7.1337779999999995D0 |#
15:48:56
_Ark_
Xach: I want to add some built-in profiling to my game engine. Mircoseconds will work for this, but I was curious how fine-grain of time lisp can get.
15:51:00
_Ark_
Yeah I figured FFI was always an option. Was wondering if there was a "standard" way to do this. For some applications nano-time is desierable
15:51:39
Shinmera
That resolution won't be useful because it'll be highly dominated by noise anyway.
15:53:58
_Ark_
I used to be an APM (Application Performance Monitoring) devleoper for the JVM. Basically a simple profiler designed to run in production. We always measured in cpu nanoseconds. In practice it ended up being useful.
15:56:08
_Ark_
Looking though some of the libraries people linked. Seems like `local-time` on sbcl is using `sb-ext:get-time-of-day` under the hood. I'll take a look at monotonic-clock next...
15:58:58
jcowan
U.S. Steel is the corporate descendant of Carnegie Steel. CMU's money didn't come from nowhere.
16:09:25
Bike
steel bank common lisp is descended from carnegie mellon university common lisp, because carnegie was a steel mogul and mellon a banker
16:11:59
_Ark_
For anyone following along, `monotonic-clock` is implemented using FFI. Here's the underlying system call: https://linux.die.net/man/3/clock_gettime
16:12:27
_Ark_
I guess my take-away is that getting the CPU time will required an FFI call (or more desirably using a library that manages the FFI for you). To Shinmera's point, this is overkill and not helpful for most applications, so micro-time is likely what you want.
16:38:22
dlowe
worse, some computers claim to know nanoseconds and then only update their nanosecond counter every microsecond or so
16:44:25
jmercouris
when I use cffi:callback to pass a callback to some C code, how can I store that in the C code? what is it a void *?
16:45:36
pjb
jmercouris: in any case, the cffi declaration of the C function, and the C function itself don't need to have the same type of parameters.
16:45:42
jackdaniel
pjb: in C standard casting function pointers to data pointers is undefined behavior
16:48:37
_death
so, struct { void (*fp)(void); } stuff; void store(void (*fp)(void)) { stuff.fp = fp; }
16:49:07
jackdaniel
jmercouris: please read this piece https://www.cprogramming.com/tutorial/function-pointers.html, I think that discussing C pointers is not very ontopic
16:49:28
Bike
function pointers and data pointers aren't interchangeable but you can use function pointers fine. declare a global variable with function pointer type, put it in a struct, whatever
16:50:01
_death
you'd also want to take a context pointer, i.e. some void pointer to store as well and pass along when calling the function pointer
16:50:08
pjb
jackdaniel: I see only a prevention of casting (void*) to float, in 6.5.4 of ISO/IEC 9899:201x Committee Draft — April 12, 2011 N1570
16:53:29
TMA
pjb: you need to consider the whole standard; undefined behavior need not be explicitely specified, the necessary condition is that the standard does not explicitely or implicitely specify it
16:54:17
pjb
TMA: yes, but then the C standard doesn't specify a Turing Complete language either. So we could stop there.
16:54:46
pjb
TMA: but if it's not formally forbidden, and all C compilers do the right thing, where's the objection?
16:55:30
TMA
pjb: embedded platforms can have function pointers bigger or smaller than data pointers
16:56:54
jackdaniel
pjb: in 6.3.2.3 (same document), pointes 7. and 8.; there is no specification about casting between object and function pointers
17:00:12
jackdaniel
it is certainly nice that it "usually works", but I think that there are architectures where normal data pointer is insufficient to store function address
17:00:26
pjb
Ok, so it could work or not, it's implementation dependent. So we'd need to cast to something like int(*)() or void(*)() perhaps. typedef void(*function_ptr)();
17:02:27
pjb
Anyways, my point was that the CFFI declaration of _death's store function above doesn't need to use the type of void(*fp)(void) as argument, but can take the cffi:callback type.
17:03:22
pjb
Said otherwise, FFIs don't validate the function signatures across languages. If it could, we wouldn't have to declare the C functions in lisp!
17:13:47
jmercouris
not to fuel the off-topic discussion, but I read somewhere that it is apparently a posix specification that it should work
17:56:15
flip214
_Ark_: SBCL shows the CPU cycles in (time), (sb-ext:call-with-timing) can give that without parsing text, and then there's (sb-impl::read-cycle-counter) ...
18:30:16
jackdaniel
that is correct, dlsym returns a void pointer, it is briefly discussed here https://en.wikipedia.org/wiki/Dynamic_loading