Hello :slightly_smiling_face: :wave: I'm really en...
# arrow
f
Hello πŸ™‚ πŸ‘‹ I'm really enjoying using Arrow! In fact, I've been using it for an in-memory object database that I'm building for fun. I have a question that I'd be very grateful for someone on the team to help with please. With Optics, why doesn't Arrow cache these? Currently Lenses are created everytime their path is accessed. e.g. this fails:
Copy code
assertEquals(Person.address.city, Person.address.city)
If these could be cached (perhaps by using
by lazy
in the generated companion properties), they can actually be used as keys in the indexes of my database, which would make expressions like this elegant and efficient:
Copy code
people.find(Person.address.city eq "Oslo")
πŸ‘‹ 1
y
That's rather interesting! Maybe there's a way we can have structural equality for these? Referential would be more efficient obviously, but I wonder if structural would be doable without needing to change how the plugins work or anything
f
referential structural would be great, functionally!
Referential would give a nice performance boost for my use-case, I think. I'm servicing 10k + queries per second .. which generates quite a lot of garbage.
I had a look at how the plugin could be adapted to generate
by lazy
values. there's quite a bit of learning curve, but perhaps I could make a PR? I don't know how much effort it would be
s
Hey @Farzad Pezeshkpour! Still super curious what your code looks like 😜 Hmm, we used to have something but probably not for the compositional part. We left this a bit to the side because we were hoping to have a better solution that's more tightly integrated into the language using Arrow-meta / compiler plugins. Sadly those still haven't seen a stable release, but I think after Kotlin 2.0 is a good time to pick this back-up. Originally my vision for this was for it to become completely synthetic, so the compiler tries to inline everything as much as possible to hand-written
copy
code or similar. Or, it generates hardcoded optics for the compositions and caches them in a top-level
val
. It seems to be mostly a time related issue that this hasn't been pushed further. Any contributions would be awesome! πŸ™ There is also #C8UK6RTHU if you have any questions, or topics/issues you'd like to discuss.
a
just to be clear, here we are talking about caching and having structural equality for the lenses themselves, right? I've tried some of this in the past, and some of the challenges are: β€’ extension properties must always have a
get()
, but indeed we could try for them to "save" their value by using some kind of
lazy
β€’ to have structural equality we may need to give a "key" to every lens (or have some special
Keyed
interface for those). For properties we can use the
KProperty
itself, but for things like
every
it's a bit more convoluted. Still, something worth trying
f
Good morning! Thanks @simon.vergauwen and @Alejandro Serrano.Mena. Apologies, I will need to be brief because of work matters: β€’ Interesting idea Simon [edit] I would love to learn more and try it out! β€’ Alejandro, yes structural equality but so that they can be used as a key into my caches. Other use cases may exist. Yes, I took the same approach with (a) an
id
property per
PLens
and (b) use of
by lazy
I wrote an embarrassingly simple Optics module that works for my use-case. It's inside my (currently private) multimodule project. After work, I can split it out with some example code to show what I mean. The code was done in haste and is ... very ugly lol
@simon.vergauwen @Alejandro Serrano.Mena In my lunchtime, I've quickly made this sample project to explain the concept and approach. The code is v quick and dirty but hopefully gets the idea across πŸ™ https://github.com/dazraf/optics-jam
πŸ”₯ 2
a
@Farzad Pezeshkpour you are fast!! I'll have a look at it this week and report back
f
cool, thanks @Alejandro Serrano.Mena
(btw, this sample code doesn't use Arrow as yet. It uses Kotlin Poet just to get the idea over. I've been studying Arrow's AST ... I think I may be able to do it using that. Who knows, maybe even one day submit a PR if I'm permitted)
a
the optics plugin is built on KSP without even Kotlin Poet, so I'm sure you'll be able to contribute πŸ˜„
f
hooray! \o/ πŸ˜„
btw, I've cloned the Arrow repo and trying to figure out how to build it. My local device is a Linux laptop. I get a lot of warnings and the build fails. Trying to figure out why ...
s
Your machine needs to be properly setup for Kotlin Multiplatform. KDoctor is the (best and) official tool for setting up -and verifying your local setup. Not sure if we can simplify this πŸ€” In the past disabling certain targets depending on the host OS was a common practice, but it turns off some of the sources which can make development annoying since local development will not reflect reality.
KDoctor works on MacOS only.
-.- sorry, not sure for Linux πŸ˜•
f
Thank you πŸ™ I tried adding
kotlin.native.ignoreDisabledTargets=true
as recommended by the gradle output. Currently getting
Copy code
Could not determine the dependencies of task ':arrow-annotations:dokkaGenerateModuleHtml'.
I'll keep working through the issues to see if I can get a working build. Will let you know how it goes.
btw, I forgot to say Good Morning!
s
Good morning ☺️
Could not determine the dependencies of task 'arrow annotationsdokkaGenerateModuleHtml'.
🀯 Try a
./gradlew --stop
in between to kill any deamons...
f
Got it working. I needed to setup the ANDROID_HOME envvar
It's building now πŸŽ‰
arrow intensifies 1
died owing to lack of ram (16GB machine) will try isolating specific steps in the build needed for a JVM build
kodee sad 1
Got a clean build with
Copy code
./gradlew compileKotlinJvm
happiness
kodee loving 1
Now dancing with the import into IDEA. An AGP version issue with the latest version of IDEA. Dealing with it 🀞
After some fiddling around with the build settings and closing down other apps to give more memory headroom, I have a local build in the IDE!