clojure-dev

Issues: https://clojure.atlassian.net/browse/CLJ | Guide: https://insideclojure.org/2015/05/01/contributing-clojure/
murtaza 2019-08-07T05:11:31.214800Z

I've created a patch to protocolize the creation of zippers. I've basically built a zip2 entirely on top of zip. This approach was taken to ensure that I don't end up removing the existing counterpart functions from zip, since that might be a breaking change. Curious to know if anyone has a different approach in mind for this. Here's the ticket along with the patch https://clojure.atlassian.net/projects/CLJ/issues/CLJ-2530?filter=allopenissues&orderby=created%20DESC

2019-08-07T05:29:32.220400Z

Did this get discussed on the mailing list at all?

2019-08-07T05:31:40.222100Z

The ticket doesn't really convey a strong sense of what is being solved to me, so I wonder if I am missing some context

alexmiller 2019-08-07T05:38:02.222900Z

zip would absolutely have been a better design with protocols (if protocols had existed when it was created)

alexmiller 2019-08-07T05:38:11.223200Z

I've written this same thing before

alexmiller 2019-08-07T05:38:34.223600Z

but just because we can do it is not a strong argument for why we should do it

alexmiller 2019-08-07T05:41:05.224300Z

perf is one possible reason

alexmiller 2019-08-07T05:43:30.225100Z

oh, looking at the patch you're actually cutting a different dimension than I thought

alexmiller 2019-08-07T05:43:57.226100Z

zippers themselves are a collection of 3 functions and I thought you were creating a protocol for that

murtaza 2019-08-07T05:44:30.227400Z

Is there not being an easy way to protocolize without creating a breaking change what makes the argument for this change less compelling?

alexmiller 2019-08-07T05:44:43.228Z

yes

murtaza 2019-08-07T05:45:06.228900Z

That's what I've done, haven't I?

2019-08-07T05:45:06.229100Z

Yeah, that is the other thing "protocolizing zippers" can mean different things, and this approach is the one I would expect the least

alexmiller 2019-08-07T05:45:24.229600Z

yes, looking at the patch, I was surprised

murtaza 2019-08-07T05:45:39.230200Z

What would be a better approach?

2019-08-07T05:45:41.230400Z

You might check out something like https://github.com/akhudek/fast-zip

alexmiller 2019-08-07T05:46:33.231400Z

even that is not what I'd expect :)

2019-08-07T05:46:33.231500Z

Although I guess that is all deftypes, no protocols

2019-08-07T05:46:53.232200Z

I feel like maybe bbloom had something

alexmiller 2019-08-07T05:46:56.232400Z

but the argument being made in that is perf

alexmiller 2019-08-07T05:47:59.233200Z

I wrote one way back when I wrote the zipper article in 2010/2011, but doesn't look I actually made a repo out of it

alexmiller 2019-08-07T05:48:39.233600Z

but to unroll back to a good question - what problem are you trying to solve?

alexmiller 2019-08-07T05:48:52.233900Z

what does this version do that the current version doesn't?

alexmiller 2019-08-07T05:50:06.234Z

you've got all the functions buried under one protocol method

alexmiller 2019-08-07T05:51:28.234200Z

I expected something like

(defprotocol Zipper 
  (branch? [this node]) 
  (children [this node]) 
  (make-node [this node children]))

alexmiller 2019-08-07T05:53:30.234500Z

tying those impls to concrete types is bad b/c you might want different functions for the same type

alexmiller 2019-08-07T05:57:01.234700Z

if dispatching on the concrete type was the idea here, I don't think it's a good one

schmee 2019-08-07T18:51:59.235900Z

can Clojure loop constructs be unrolled by the JIT under any circumstance?

ghadi 2019-08-07T18:53:04.236100Z

sure

alexmiller 2019-08-07T18:55:11.237Z

they're pretty much the same as Java loops in the bytecode

schmee 2019-08-07T19:00:26.237800Z

I thought the JIT only unrolled counted loops (like for with a constant stride)?

2019-08-07T19:00:56.238200Z

the jit only sees bytecode, for loops don't exist in the bytecode

2019-08-07T19:01:15.238700Z

so what the jit can unroll are particular patterns of jumps in the bytecode

alexmiller 2019-08-07T19:07:37.238900Z

GOTO!

schmee 2019-08-07T19:25:09.241400Z

this might be nonsense but I’ll ask anyway: Maurizio Cimadamore mentioned in the Panama update from JVMLS that most loop optimizations don’t apply when using longs, am I correct that this would be an issue for Clojure loops as well since all primitive math is done with longs? https://youtu.be/r4dNRVWYaZI?t=2100

schmee 2019-08-07T19:32:10.242700Z

hah, it actually does seem to be the case: I have a Java loop with that gets unrolled when the loop variable is an int, but not when it’s a long, and the equivalent Clojure loop also does not get unrolled

ghadi 2019-08-07T19:49:57.243200Z

https://bugs.openjdk.java.net/browse/JDK-8223051

👍 1