dev-tooling

ericdallo 2025-04-10T21:19:55.553599Z

Any thoughts on how to really know on middleware side how much time took from REPL start trigger to really become available to user?

ericdallo 2025-04-10T21:21:14.741039Z

I tried (.getUptime (ManagementFactory/getRuntimeMXBean)) suggestion from @jpmonettas but it's not even close to the real time, I'm getting it on the first op received (clone). Testing with a project that takes 39s to repl become ready to use, it returns 19s which doesn't seem right

ericdallo 2025-04-10T21:21:51.020729Z

not sure lein could be affecting there as it starts a new JVM or so, thinking that will be hard to know unless clients provide that time from their side

oyakushev 2025-04-10T21:22:54.517199Z

Not out of the box. You can monkey-patch start-server (https://github.com/nrepl/nrepl/blob/47aa27b52d09ea5636272d8b93ba68a3824c808d/src/clojure/nrepl/server.clj#L178) to record the timestamp once it finishes loading and subtract it from the JVM starting time.

ericdallo 2025-04-10T21:23:48.392329Z

hum, you mean under the hood this function will always be called and I can kind of wrap it to get the time?

oyakushev 2025-04-10T21:24:26.244659Z

Yeah. But wrapping it by monkey-patching might be somewhat tricky. You want the patch to happen before the server is started

oyakushev 2025-04-10T21:24:36.367719Z

> not sure lein could be affecting there as it starts a new JVM or so Yeah, lein uses two JVMs, so it may be the reason

ericdallo 2025-04-10T21:26:37.120489Z

even so, that wouldn't help I guess, I want the time the user took waiting for the repl to be available, besides the lein JVM issue, getting the time start-server was called seems to not ideal as stuff happened before for that to happen

oyakushev 2025-04-10T21:26:40.431219Z

You can wrap your test running function on the bash side in a script that puts the startup timestamp onto the env

🤯 1
oyakushev 2025-04-10T21:27:05.426079Z

JVM_STARTING_TIME=$(date +%s) lein ...

oyakushev 2025-04-10T21:27:30.627099Z

Then inside the process subtract the current timestamp from that value – gives you "real" time from start

ericdallo 2025-04-10T21:27:35.609149Z

haha yah, but I'd love to fix that in a good way as this is one of the features of https://github.com/ericdallo/metrepl that I'm building

oyakushev 2025-04-10T21:28:59.475489Z

Then .getUptime is the best you have. Of course, it cannot know if the build tools and everything was fooling around for minutes before they finally started this jvm

ericdallo 2025-04-10T21:31:19.011799Z

yeah, I was thinking how feasible would be to accept a request-timestamp in clonerequest:see_no_evil:

ericdallo 2025-04-10T21:31:48.048779Z

that would basically solve all lein time issues, although needs PRs on most editors (but I did that recently so I'm ok with that )

oyakushev 2025-04-10T21:32:17.778939Z

Not sure what this will give you

oyakushev 2025-04-10T21:32:34.664019Z

The client doesn't send clone until it connects to the server

oyakushev 2025-04-10T21:32:43.022789Z

You need a live socket for that

oyakushev 2025-04-10T21:32:58.027439Z

The socket won't be available until the server starts

ericdallo 2025-04-10T21:34:03.794359Z

ah true

ericdallo 2025-04-10T21:34:08.555739Z

I mean

ericdallo 2025-04-10T21:34:33.721019Z

yeah, each client would need to store the timestamp in memory of when started the repl command and then pass that on clone request when happen

ericdallo 2025-04-10T21:34:38.511349Z

kinda tricky

oyakushev 2025-04-10T21:35:00.440329Z

"Time until REPL starts" from the strictly-client perspective only makes sense for the client that is also the initializer of the server. This is a partial case of nrepl usage but not a generic one.

ericdallo 2025-04-10T21:35:16.250879Z

yeah, indeed

ericdallo 2025-04-10T21:35:29.904929Z

I wish there was a way to solve that

oyakushev 2025-04-10T21:35:56.508019Z

> yeah, each client would need to store the timestamp in memory of when started the repl command STARTUP_TIMESTAMP=$(date.. 😂

ericdallo 2025-04-10T21:36:25.143299Z

yeah true haha

oyakushev 2025-04-10T21:36:41.047759Z

Again, it seems you are trying to solve too broad of an issue

oyakushev 2025-04-10T21:37:02.028479Z

You can measure the time from JVM start to REPL being alive, and that will be generic

oyakushev 2025-04-10T21:37:45.428569Z

But it won't account for all the prior stuff that happens around that JVM (build tools, maybe downloading dependencies, who knows). And I doubt that REPL/nrepl/middleware can/should know about that

oyakushev 2025-04-10T21:38:21.579549Z

People who want to know this information can solve it for their particular setups, but that won't be generic for sure

ericdallo 2025-04-10T21:38:54.778719Z

good point

ericdallo 2025-04-10T21:39:47.192759Z

thanks for the inputs

🤝 1
2025-04-11T00:11:03.857919Z

@ericdallo yeah, lein start two JVMs and that is probably the difference. Have you tried lein trampoline, I think that should do it with one JVM

👍 1