Skip to content
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

cljs instrumentation DX - clear metadata schemas before collection #745

Merged

Conversation

dvingo
Copy link
Contributor

@dvingo dvingo commented Aug 25, 2022

During development with instrumentation enabled function schemas declared
with metadata were never deregistered once they were collected.
Thus if a developer removed a schema on a function it would always be instrumented.
This commit adds a flag on metadata schemas to distinguish them from => style schemas
and then removes them before running collection again in malli.dev.cljs/start!

This resolves
#744

demo of metadata schema being added and removed (this is in the sample app in the malli codebase)

malli_inst_demo2.mov

Edit:
I realized the same issue will happen with => function schemas: once it is registered and instrumented it would always be instrumented. For this use-case I added a dev-time helper malli.dev.cljs/deregister-function-schemas! which will allow a user to remove all registered schemas to get a clean instrumentation state.

During development with instrumentation enabled function schemas declared
with metadata were never deregistered once they were collected.
Thus if a developer removed a schema on a function it would always be instrumented.
This commit adds a flag on metadata schemas to distinguish them from => style schemas
and then removes them before running collection again in malli.dev.cljs/start!
Copy link
Contributor

@ingesolvoll ingesolvoll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this a bit. If I remove the :malli/schema metadata, the instrumentation goes away. But if I re-add the metadata on the same function, it is no longer instrumented.

@@ -17,6 +18,8 @@
(defn start!* [env options]
`(do
;; register all function schemas and instrument them based on the options
;; first clear out all metadata schemas to support dev-time removal of metadata schemas on functions - they should not be instrumented
~(m/-deregister-metadata-function-schemas! :cljs)
Copy link
Contributor

@danielcompton danielcompton Aug 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be called on stop! as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is not needed on stop! because there are two separate concerns:

  • collecting the functions that have schemas and storing them in a hashmap in an atom
  • starting and stopping instrumentation

the -deregister helper is to deal with ensuring those functions stored in the atom are up to date with the code, whereas stop!ing is only concerned with replacing the instrumented function with its original function.

I could see some weird interaction happening with hot reloading where you both remove the schema and change the function implementation, and then call stop! which may replace the updated function with the original function.
But this would only affect one reloaded app instance, you would just have to hot-reload again and the newest function will be in place.

I tried out running stop! after removing metadata and things work as expected, but of course if you run into something strange let me know.

@dvingo
Copy link
Contributor Author

dvingo commented Aug 26, 2022

I tested this a bit. If I remove the :malli/schema metadata, the instrumentation goes away. But if I re-add the metadata on the same function, it is no longer instrumented.

Do you have video demo or a reproduction repo to look at? The video I posted above is doing what you described, so a repo would help.

@ingesolvoll
Copy link
Contributor

@dvingo Sorry, I suspect this is coming from the way our re-frame variant caches subscriptions and events, and probably not relevant to your change. Will report back if I find any evidence pointing elsewhere.

@ikitommi
Copy link
Member

Just say when all good and I'll merge this.

@dvingo
Copy link
Contributor Author

dvingo commented Aug 29, 2022

I am good with this being merged. If there are further complications another issue can be opened.

@ikitommi ikitommi merged commit 48c344b into metosin:master Aug 31, 2022
@ikitommi
Copy link
Member

Merged it is then, big thanks for the super quick fix.

@dvingo dvingo deleted the fix-removing-metadata-fn-schemas-instrument branch May 5, 2023 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants