-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proof of concept for attaching :doc metadata to generate functions #98
base: master
Are you sure you want to change the base?
Conversation
@genmeblog, maybe you can improve on it. |
I removed the duplication of the help logic. BUT its slow. |
Can be used like this:
Help generation is as well memoized, so at least fast on second call |
It does work as well for Calva, not sure why it failed as I tried. |
Maybe instead of
|
Yes, I thought about it. Ideally we could speed it up..., but likely not possible. Not per library. |
Yes, you're right, so maybe an argument to |
FYI: |
In my view the "slow R package loading" due to help loading is acceptable, as it happens only once per R package, then its cached. |
We can also alter vars in the background I think. |
I am pretty happy with it now. The :doc gets now changed to be "help" via alter-meta! in a |
Remark: as we use now a "future" we get the 60 seconds waiting when clojure shuts down |
time clj -e "(require '[clojisr.v1.r :as r])(r/require-r '[utils])"
real 1m10.797s
user 0m29.738s
sys 0m0.844s Here we see the 60 seconds delay. vs time clj -e "(require '[clojisr.v1.r :as r])(r/require-r '[utils])(System/exit 0)"
real 0m14.728s
user 0m29.386s
sys 0m0.827s same duration as: time clj -e "(require '[clojisr.v1.r :as r])(r/require-r '[utils])(shutdown-agents)"
real 0m15.212s
user 0m29.055s
sys 0m0.767s So people doing scripts just need to remember to add it. |
The latest change removes the future, and uses (.start (Thread ,,) instead. (r/require-r '[base]) |
The 60 second problem is already present on "main". Once we start the R session in any form, So it is not related to any changes I did in this PR. |
Maybe this is the reason? https://github.com/scicloj/clojisr/blob/master/src/clojisr/v1/r.clj#L201-L203 Are you able to verify this by turning this off for tests (I can't do this now)? |
src/clojisr/v1/require.clj
Outdated
(add-to-ns ns-symbol r-symbol r-object)) | ||
(run! | ||
(fn [[r-symbol r-object]] | ||
(assoc-doc-to-meta! ns-symbol r-symbol r-object)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In rich packages you'll run zillions of threads. The whole loop should be run in one thread.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have tried this before, in a future.
That introduced a "noticeble lack" when evaluating:
(r/require-r '[base])
(r/require-r '[stats])
(unless we put a Thread/sleep in the beginning. See comments above)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found a trick.....
So we do the slow reading of the help 'on demand'
(defn- assoc-doc-to-meta! [ns-symbol r-symbol r-object]
(alter-meta!
(get (ns-publics ns-symbol) r-symbol)
assoc :doc (reify Object
(toString [this] (safe-help r-object)))))
This works in vscode.
the value of the :doc is now not a string, but a function , implementing "toString".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I asked about this on slack, let's see.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a good idea it seems, and I somehow agree.
Docstrings are supposed to be strings, that's it.
Even if all the tools that you use accept non-strings, relying on it would be wrong.
The ns macro explicitly checks for string?, as does defprotocol.
find-doc works only on strings and would throw on anything else.
And so on.
There are four alternatives that I see:
Just tolerate the loading time
Make every docstring the same, and in it mention that a user should call something like generate-docs that would take some time and update run-time docstrings
Same as the above, but instead of generate-docs it would be custom-doc that retrieves the docstring just for the provided function
If the R libraries are known in advance, generate Clojure code from them, along with all the docstrings
In last commit I came back to your original proposal of adding an option to require-r, by default "false". |
My last change breaks: |
Ok, I made a new try of a parameter 'generate-doc-strings?', default to false |
Does it work now? |
yes |
This is very draft.
I was not able to re-use the existing "help" , and need a hack to have a session.
And on this I am not sure, how to do better.