workspace
stringclasses 4
values | channel
stringclasses 4
values | text
stringlengths 1
3.93k
| ts
stringlengths 26
26
| user
stringlengths 2
11
|
---|---|---|---|---|
clojurians | clojure | my component creates the handler function, and passes it to the function that starts the http server (along with some middleware that the component also creates) | 2017-11-04T17:18:38.000044 | Margaret |
clojurians | clojure | <@Margaret> ok, so in my case, I should just make Mongo a dependency of the Pedestal component, and any time such a handler is invoked which requires mongo (eg in case of a "list of products" JSON REST service), pass in the Mongo connection ? | 2017-11-04T17:22:42.000045 | Lieselotte |
clojurians | clojure | yeah - and in fact you can pass in a subset of the component map - at some point you might also need a postgres connection, or some initialized resource | 2017-11-04T17:23:37.000103 | Margaret |
clojurians | clojure | <@Margaret> hm. two problems with that. 1. In Pedestal, I'm not in a very direct relationship with the handler.. I mean there is a router in between, etc. So simply I don't see how I could pass the connection (or component) down the chain so it finally reaches that method where it is needed. 2. Actually MongoDb is not a dependency of my Pedestal component, but of my business logic. Eg just because Pedestal is restarted for some reason, there is no reason to also restart the MongoDb component | 2017-11-04T17:28:43.000054 | Lieselotte |
clojurians | clojure | I've never seen any reason to restart components piecemeal - it's fast enough that I just restart the whole thing. You can pass values that handlers need by attaching them to the request before it hits the router. | 2017-11-04T17:30:10.000019 | Margaret |
clojurians | clojure | the job of the component system is to ensure that all the states are coherent - starting and stopping as one big system is part of what makes that work | 2017-11-04T17:30:53.000026 | Margaret |
clojurians | clojure | <@Margaret> ok, then I'll try to make it work this way :slightly_smiling_face: thanks! | 2017-11-04T17:35:34.000028 | Lieselotte |
clojurians | clojure | <@Margaret> btw I'm also new to Mongo, is actually sharing a connection recommended? or should a connection be built up on every request? | 2017-11-04T17:41:45.000005 | Lieselotte |
clojurians | clojure | (I mean http request here) | 2017-11-04T17:42:09.000079 | Lieselotte |
clojurians | clojure | hm the <https://github.com/danielsz/system/blob/master/src/system/components/mongo.clj> creates a connection on component start, so I guess this is intended to be shared accross all users/requests (I was just wondering if there is sort of a similar thing like that's connection pooling to RDBMSs) | 2017-11-04T17:44:18.000007 | Lieselotte |
clojurians | clojure | ah ok, according to <http://clojuremongodb.info/articles/connecting.html> monger does connection pooling inside, so I can just use my single "connection" and this will get pooled by the library itself | 2017-11-04T17:47:09.000054 | Lieselotte |
clojurians | clojure | I need help optimizing this numeric clojure code.
input: float array of size n
output: float array of size (- n 1)
where each output[i] = input[i] + input[i+1]
```
(def n 1000000)
(def x (float-array (range n)))
(def y (float-array (- n 1)))
(doseq [i (range (- n 1))]
(aset y i (float (+ (aget x i)
(aget x (+ i 1))))))
```
I'm on a GHz machine. loading + adding + storing 1M numbers should not take 10s of seconds
how do I type hint / unbox / all types of crazy things ot make this fast ? | 2017-11-04T18:15:24.000019 | Berry |
clojurians | clojure | <@Berry> no idea, but this benchmarking library is probably useful <https://github.com/hugoduncan/criterium> | 2017-11-04T18:17:14.000076 | Lieselotte |
clojurians | clojure | ```(doseq [i (range (- n 1))]
(aset-float y i (+ (aget ^floats x i)
(aget ^floats x (+ i 1)))))``` | 2017-11-04T18:24:33.000021 | Jonas |
clojurians | clojure | that’s a lot faster | 2017-11-04T18:24:38.000029 | Jonas |
clojurians | clojure | there’s probably still room for improvement | 2017-11-04T18:24:49.000089 | Jonas |
clojurians | clojure | <@Berry> | 2017-11-04T18:24:57.000050 | Jonas |
clojurians | clojure | as an aside,```(float-array
(map (fn [a b]
(+ a b))
x (rest x)))``` | 2017-11-04T18:39:13.000102 | Jonas |
clojurians | clojure | <@Jonas>: that reduced runtime by about 99% | 2017-11-04T18:39:15.000107 | Berry |
clojurians | clojure | seems to work pretty well | 2017-11-04T18:39:17.000046 | Jonas |
clojurians | clojure | (the aset-float, ^floats solution) | 2017-11-04T18:39:31.000045 | Berry |
clojurians | clojure | the `map` version I think is a little more straightforward | 2017-11-04T18:39:53.000079 | Jonas |
clojurians | clojure | albeit, slightly slower | 2017-11-04T18:40:15.000015 | Jonas |
clojurians | clojure | but not nearly as as slow as the initial `doseq` version | 2017-11-04T18:40:36.000025 | Jonas |
clojurians | clojure | ```(def y (float-array
(map (fn [a b]
(+ a b))
x (rest x))))``` | 2017-11-04T18:41:17.000061 | Jonas |
clojurians | clojure | this is my fault for not clarifying this upfront, but I really have to modify an existing float-array (the 'posed problem' was a 'minimal case' of my 'actual problem'), so (float-array ... (map ... )) won't work | 2017-11-04T18:41:41.000131 | Berry |
clojurians | clojure | the best so far is your solution of:
```
(doseq [i (range (- n 1))]
(aset-float y i (+ (aget ^floats x i)
(aget ^floats x (+ i 1)))))
``` | 2017-11-04T18:41:58.000085 | Berry |
clojurians | clojure | I wonder if there is a way to know of the + has boxing/unboxing involved | 2017-11-04T18:42:12.000023 | Berry |
clojurians | clojure | <@Berry> some info straight from alex miller: <http://insideclojure.org/2014/12/15/warn-on-boxed/> | 2017-11-04T18:43:35.000080 | Willow |
clojurians | clojure | so now we're at:
```
(set! *unchecked-math* :warn-on-boxed)
(def n 100000000)
(def x (float-array n))
(def y (float-array (- ^long n 1)))
(doseq [i (range (- ^long n 1))]
(aset-float y i (+ (aget ^floats x i)
(aget ^floats x (+ ^long i 1)))))
```
and the remaining thing to do is to call disassemble and see what's goingon there | 2017-11-04T18:46:25.000091 | Berry |
clojurians | clojure | unfortunately, disassemble is throwing an exception right now | 2017-11-04T18:52:29.000057 | Berry |
clojurians | clojure | <@Berry> As an alternative, you could also consider writing this performance-critical section in Java and calling it via interop. (Passing on a suggestion from this channel not too long ago.) | 2017-11-04T18:57:22.000004 | Araceli |
clojurians | clojure | I'm getting an error in my Datomic setup that I'm not being able to get around. Here's what I have, a transactor running, a console connected to this transactor and a peer server connected to the same transactor. Whenever I try to connect to the peer server from the bin/repl found in the Datomic installation directory it works fine, here's an example output:
```
user=> (require '[clojure.core.async :refer (<!!)]
'[datomic.client :as client])
nil
user=> (<!! (client/connect {:db-name "clj-twitter"
:account-id client/PRO_ACCOUNT
:secret "mysecret"
:region "none"
:endpoint "localhost:8998"
:service "peer-service"
:access-key "myaccesskey"}))
#object[datomic.client.impl.types.Connection 0x2a235b8e "#datomic.client.impl.types.Connection[{:t 63, :next-t 1000, :account-id \"00000000-0000-0000-0000-000000000000\", :db-name \"clj-twitter\", :db-id \"datomic:dev://localhost:4334/clj-twitter\", :timeout 60000}]"]
```
But it doesn't work that well when I try the same from the REPL inside my project:
```
user=> (require '[clojure.core.async :refer (<!!)]
#_=> '[datomic.client :as client])
2017-11-04 21:21:22.610:INFO::nREPL-worker-0: Logging initialized @9976ms
nil
user=> (<!! (client/connect {:db-name "clj-twitter"
#_=> :account-id client/PRO_ACCOUNT
#_=> :secret "mysecret"
#_=> :region "none"
#_=> :endpoint "localhost:8998"
#_=> :service "peer-service"
#_=> :access-key "myaccesskey"}))
ClassNotFoundException org.eclipse.jetty.util.thread.NonBlockingThread java.net.URLClassLoader.findClass (URLClassLoader.java:381)
```
One thing I noticed is that the REPL from the Datomic installation directory is using Clojure 1.9.0-alpha15, while my project is using Clojure 1.8.0.
Does anyone knows or have an idea of what I'm possibly doing wrong? | 2017-11-04T19:39:26.000001 | Ahmad |
clojurians | clojure | <@Ahmad> I haven't worked with Datomic, so I can't speak to that. But, in the past when I've encountered `ClassNotFoundException`, it's because I had my classpath set up incorrectly one way or another. | 2017-11-04T20:02:55.000053 | Araceli |
clojurians | clojure | <@Ahmad> What build tool are you using? Have you declared all the appropriate dependencies as required by the documentation that you're following? | 2017-11-04T20:04:03.000017 | Araceli |
clojurians | clojure | <@Araceli> I think it's somehow related to my dependencies, some sort of conflict between versions, because I just created a new leiningen project and it worked there. I have also found some Stack Overflow questions and old conversations from the <#C03RZMDSH|datomic> channel where another person were facing the same problem | 2017-11-04T20:08:00.000036 | Ahmad |
clojurians | clojure | It seems to be related to ring as I'm also using it in my project and the fact that it uses Jetty on a certain version... | 2017-11-04T20:10:03.000038 | Ahmad |
clojurians | clojure | <@Ahmad> I see. In that case, you may need to bump up some versions. Although, of course, that has other effects on the project as a whole. | 2017-11-04T20:12:43.000055 | Araceli |
clojurians | clojure | <@Araceli> I don't think I can, my dependencies are at latest versions | 2017-11-04T20:17:52.000031 | Ahmad |
clojurians | clojure | <@Ahmad> That is a bit unexpected, then. Sorry, but it doesn't match what I've seen, so I don't think I know how to help you, unfortunately. | 2017-11-04T20:18:47.000059 | Araceli |
clojurians | clojure | <@Araceli> I have an idea, I'm inspecting the dependency tree of a new leiningen project from which the connection works and then I will compare it to the dependency tree of my project with lein deps :tree | 2017-11-04T20:21:51.000048 | Ahmad |
clojurians | clojure | And, if it turns out a transitive dependency is resolving to a different version than what works, you can always explicitly pin it. | 2017-11-04T20:22:33.000015 | Araceli |
clojurians | clojure | <@Araceli> Oh, by the way no problem, I appreciate your attention :) | 2017-11-04T20:22:58.000038 | Ahmad |
clojurians | clojure | The problem in, for example, NodeJS land is that, sometimes, _there does not exist a set of mutually compatible versions for some sets of dependencies_. For what it's worth, Java land I feel like has been better about this on average. | 2017-11-04T20:23:34.000044 | Araceli |
clojurians | clojure | I still have to learn how that thing you mentioned works | 2017-11-04T20:23:35.000030 | Ahmad |
clojurians | clojure | If there is a transitive dependency (not directly declared in your dependencies, but pulled in as a result of what was directly declared) that needs to be at a specific version, you can pin it (declare it explicitly, at the version needed, in your dependencies). | 2017-11-04T20:25:01.000057 | Araceli |
clojurians | clojure | <@Araceli> Oh, now it makes sense. Merging what you said with what I'm seeing in the comparison of both dependency trees. It seems that the `ring/ring-jetty-adapter` dependency in my project contains a transitive dependency as you said to `org.eclipse.jetty/jetty-io` which is also used by `com.datomic/clj-client`, but because it was already available for ring it was not downloaded for datomic. | 2017-11-04T20:33:05.000048 | Ahmad |
clojurians | clojure | Hopefully, you can find a version that makes everything happy. | 2017-11-04T20:33:42.000013 | Araceli |
clojurians | clojure | Yup, I had to add a `:exclusions` modifier for `org.eclipse.jetty/jetty-io` and it worked fine. Thanks for the help <@Araceli>! | 2017-11-04T20:46:02.000019 | Ahmad |
clojurians | clojure | You're welcome. Actually, thank you for explaining, because I learned something new there, also. | 2017-11-04T20:46:53.000027 | Araceli |
clojurians | clojure | :) | 2017-11-04T20:47:11.000030 | Ahmad |
clojurians | clojure | <@Berry> instead of aset in a doseq, use amap or areduce for performance | 2017-11-04T21:05:08.000088 | Margaret |
clojurians | clojure | <@Margaret>: in the full problem. I am modifying an existing float-array -- amap is out of the question; also, areduce only returns one item right? | 2017-11-04T21:06:18.000002 | Berry |
clojurians | clojure | an array is one item, but areduce will walk an array input faster than doseq will | 2017-11-04T21:06:48.000057 | Margaret |
clojurians | clojure | have you tried using your same array as the ret in amap? | 2017-11-04T21:07:24.000050 | Margaret |
clojurians | clojure | it should work | 2017-11-04T21:07:30.000015 | Margaret |
clojurians | clojure | generalized seq-oriented code is not going to be as fast as array specific code for the kind of thing you are doing | 2017-11-04T21:08:03.000048 | Margaret |
clojurians | clojure | <@Margaret>: this is my fault, my general problem is:
I have matrices A, B, C
I have a function f
I want each eleme of A[i, j] to be repalced with f(A[i-1, j], A[i, j-1], B[i, j], C[i, j])
I don't think areduce / amap is right for this
I posted a much simpler questino (for which areduce/amap works fine) mainly to learn how to do 'numeric unboxing stuff' in clojure | 2017-11-04T21:08:51.000015 | Berry |
clojurians | clojure | honestly beyond some very simple levels of complexity, just write some java | 2017-11-04T21:09:35.000047 | Margaret |
clojurians | clojure | if unboxing matters that much, it's easier | 2017-11-04T21:09:44.000076 | Margaret |
clojurians | clojure | yeah; I'm seriously considering doing part clojure + part scala (this problem arises from dealing with a scala library in particular) | 2017-11-04T21:10:21.000035 | Berry |
clojurians | clojure | also a multi-dimensional array is an array of arrays right? so you just need nested array ops | 2017-11-04T21:10:29.000016 | Margaret |
clojurians | clojure | the library I'm using has blas / vectorized tensor ops | 2017-11-04T21:10:52.000042 | Berry |
clojurians | clojure | OK - what's the actual type? | 2017-11-04T21:11:02.000081 | Margaret |
clojurians | clojure | unfortunately, I'm doing something dynamic-programmikng ish, where A[i,j] dedpends on A[i-1, j] A[i, j-1] | 2017-11-04T21:11:07.000041 | Berry |
clojurians | clojure | "actual type?' <-- I don't get what you are asking | 2017-11-04T21:11:46.000008 | Berry |
clojurians | clojure | like what does (type A) return. I would assume `[[F` | 2017-11-04T21:16:36.000022 | Margaret |
clojurians | clojure | so that you would use `(aget A 0 0)` to get the first item, etc. | 2017-11-04T21:17:18.000015 | Margaret |
clojurians | clojure | Hey folks, I'm trying to understand how to wrap `ServerSocketChannel` with `core.async`... can someone point me towards the right direction? | 2017-11-04T23:57:35.000005 | Carly |
clojurians | clojure | for side-effecty looping, does clojure have something faster than
```
(doseq [i (range n)]
...)
```
or is that the standard, optimal way to od it? | 2017-11-05T01:41:25.000012 | Berry |
clojurians | clojure | run! | 2017-11-05T01:41:52.000053 | Weston |
clojurians | clojure | I can't believe <https://clojuredocs.org/clojure.core/run!is> a real function -- somehow I've managed to never hear of it all these years | 2017-11-05T01:43:38.000045 | Berry |
clojurians | clojure | I’d expect `loop`/`recur` to be the fastest way available, as it should be closer to the metal than other options built on reduce etc… If performance matters so much measure it, it might be negligible in practice, and reduce/run! etc will probably be nicer. | 2017-11-05T06:54:21.000037 | Magdalena |
clojurians | clojure | any compojure api users here? what's the url supposed to be if you want to send a query param set? specifying {id :- [Long] []} for "query?id=0&id=1=3" works fine but expecting a set, i.e. {id :- #{Long} #{}} gives me "{:id (not (set? ["0" "1" "3"]))} | 2017-11-05T12:59:30.000070 | Douglass |
clojurians | clojure | the documentation on that is ridiculously thin or I just can't find the right place | 2017-11-05T12:59:54.000119 | Douglass |
clojurians | clojure | if I'm doing tensor math, should I just accept that any pure clj+java solution is going to be about 10x slower than C ? | 2017-11-05T13:00:51.000076 | Berry |
clojurians | clojure | ```
(cc/quick-bench
(let [n (* 10 1000 1000)
z (float-array n)]
(doseq [^long i (range 1 n)]
(aset-float z i
(float i)))))
```
results in:
```
Evaluation count : 6 in 6 samples of 1 calls.
Execution time mean : 514.302217 ms
Execution time std-deviation : 1.078130 ms
Execution time lower quantile : 512.321577 ms ( 2.5%)
Execution time upper quantile : 515.160140 ms (97.5%)
Overhead used : 2.944295 ns
```
does this seem right 10M aset-float takes 500ms ==> each aset-float takes 50ns ?
this seems a bit high, as I expect, on a GHz CPU, for each aset-float to take about 1ns | 2017-11-05T13:09:59.000092 | Berry |
clojurians | clojure | <@Berry> remember what I said about amap? on my machine that benches 405ms, and this benches 26 ms
```
(let [n (* 10 1000 1000)
z (float-array n)
indexes (range 1 n)]
(cc/quick-bench
(amap z i r
(float i))))``` | 2017-11-05T13:24:58.000030 | Margaret |
clojurians | clojure | <@Berry> it does the same thing, 20 times faster, you rejected what I was saying without even trying it | 2017-11-05T13:26:28.000032 | Margaret |
clojurians | clojure | notice that I don't need to use r or z - for your math where you need to look at other indexes of the array, r and z are there (plus i to do math on for index math) - it's much more general than you think | 2017-11-05T13:27:26.000062 | Margaret |
clojurians | clojure | <@Margaret>: I tried it just now; $&@($#* amap is fast | 2017-11-05T13:27:40.000061 | Berry |
clojurians | clojure | maybe you'll listen next time | 2017-11-05T13:27:49.000082 | Margaret |
clojurians | clojure | :slightly_smiling_face: | 2017-11-05T13:28:00.000051 | Berry |
clojurians | clojure | not sure if it matters, but the two different snippets aren’t measuring the same thing | 2017-11-05T13:28:06.000034 | Jonas |
clojurians | clojure | one is creating the float array in the benchmark, while the other is not | 2017-11-05T13:28:18.000013 | Jonas |
clojurians | clojure | <@Jonas> it's a silly refactor I can undo :smile: | 2017-11-05T13:28:26.000062 | Margaret |
clojurians | clojure | yea, i don’t think it would change the results too much | 2017-11-05T13:28:41.000053 | Jonas |
clojurians | clojure | I also benchmarked that refactor on the original, it makes it slower | 2017-11-05T13:28:43.000083 | Margaret |
clojurians | clojure | or more likely ,the difference was less than epsilon haha | 2017-11-05T13:29:55.000123 | Margaret |
clojurians | clojure | yeah, my quick bench says pulling the quick-bench to the outside again adds .2 ms to the run time | 2017-11-05T13:30:38.000057 | Margaret |
clojurians | clojure | great oracle of <@Margaret>, can you show me how to make this code faster too? (note that computing a[i] depends on a[i-1] which makes me unsure how to use amap)
```
(cc/quick-bench
(let [n (* 100 1000 1000)
dst (float-array n)
out (float-array n)]
(aset out 0 (aget ^floats dst 0))
(aset out 1 (aget ^floats dst 1))
(aset out 2 (aget ^floats dst 2))
(doseq [^long i (range 3 n)]
(aset out i
(min
(+ (aget ^floats dst (- i 0))
(aget ^floats out (- i 2)))
(+ (aget ^floats dst (- i 1))
(aget ^floats out (- i 1)))
(+ (aget ^floats dst (- i 2))
(aget ^floats out (- i 0))))))))
```
my current bench output is:
```
Evaluation count : 6 in 6 samples of 1 calls.
Execution time mean : 1.578544 sec
Execution time std-deviation : 21.633538 ms
Execution time lower quantile : 1.548456 sec ( 2.5%)
Execution time upper quantile : 1.599705 sec (97.5%)
Overhead used : 2.944295 ns
``` | 2017-11-05T13:38:00.000131 | Berry |
clojurians | clojure | <@Berry> like I said, the bindings i, r, z allow you to access index, original, output respectively - you can do math on i and do an array lookup on r or z | 2017-11-05T13:38:36.000089 | Margaret |
clojurians | clojure | the weird part is starting on item index 3, you'll need a conditional clearly (or maybe just copy the input back to the first 4 indexes of the output, to skip the conditional on each iteration) | 2017-11-05T13:40:46.000082 | Margaret |
clojurians | clojure | <@Margaret>: amap just sped up my code by a factor of 10. I'm not sure what you could have done to get me to take amap seriously earlier, but I'm glad you kept repeating it. | 2017-11-05T13:56:36.000007 | Berry |
clojurians | clojure | i thought part of the problem was that it doesn’t modify the array in place | 2017-11-05T13:58:54.000016 | Jonas |
clojurians | clojure | you can do that inside amap - if you want to | 2017-11-05T13:59:19.000082 | Margaret |
clojurians | clojure | maybe areduce is better if that is what you are trying to do actually | 2017-11-05T13:59:34.000080 | Margaret |
clojurians | clojure | nobody says the accumulated value maintained by areduce can't be the input | 2017-11-05T13:59:46.000040 | Margaret |
clojurians | clojure | alternatively `amap` is only like 10 lines of code | 2017-11-05T14:00:12.000100 | Jonas |
clojurians | clojure | ```(defmacro amap
"Maps an expression across an array a, using an index named idx, and
return value named ret, initialized to a clone of a, then setting
each element of ret to the evaluation of expr, returning the new
array ret."
{:added "1.0"}
[a idx ret expr]
`(let [a# ~a
~ret (aclone a#)]
(loop [~idx 0]
(if (< ~idx (alength a#))
(do
(aset ~ret ~idx ~expr)
(recur (unchecked-inc ~idx)))
~ret))))``` | 2017-11-05T14:00:15.000016 | Jonas |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.