-
Notifications
You must be signed in to change notification settings - Fork 32
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
Make classpath scanning optional #96
Comments
Regarding naming, if new library is the preferred route, maybe we could take some inspiration from the name of the component we have in Spring ( |
Actually, maybe we should start by asking a simple question: why does webjars need classpath scanning? What are the use cases that supports? |
I haven't inspected This is because Bower GitHub variant does not have as static path to You can observe these differences by taking a look at, for example, Bootstrap WebJar in different variants:
|
Another thing to consider, I originally learned about spring-projects/spring-framework#27619 after opening spring-projects/spring-boot#31560 because Spring Boot wasn't picking up That led me to open #86, and I think that if what we're discussing here end up being part of |
I suspect that we may only support “npm style” webjars, but that’s OK by me - if it’s documented it should be fine for everyone IMO. If we want Spring Boot users to be able to take advantage, I think @vpavic’s argument suggests that the best way to implement this is to make the classpath scanning lazy in the existing library - only use it if direct lookup fails. I haven’t looked at the code yet but that seems like a feasible solution. |
Hmm, why do you think it's only NPM variant we can support? The way I see it, Classic and NPM variant are basically equals in terms of the way they are resolved from the classpath. Bower GitHub seems like the only one that isn't straightforward (I'm ignoring Bower Original variant as webjars.org says it's deprecated). |
You’re probably right. I suppose I should rephrase what I said as “I don’t care if we can only support NPM packages”. It’s a bonus if some other layouts work but I don’t think it’s worth a lot of additional effort. |
Here's an attempt at a small step that delivers something useful: https://github.com/dsyer/webjars-locator-core/tree/version-locator. It adds a new utility |
After the interim rise of activity to resolve this there seems to be some loss of traction again. I can't stretch enough how much of an impact the classpath scanning has. Especially on bigger projects and bigger test suites I see a major portion of allocations being caused by this. Which in turn triggers GC again, which has an impact on CPU and timings. Here's a (large) project where 17% of allocations are spent on only classpath scanning during tests. I've shared one in the original Spring-Framework issue that even has up to 60%. What's especially bad in the Spring case it's that it's doing the classpath scanning multiple times. (Basically once per I can workaround a few places where I have control over the code, but it would be really better if this would be solved for good in the underlying libraries. Cheers, |
Sorry this took so long. I've been trying to wrap my head around everything that exists today and why. Here are some initial thoughts...
Overall I think the best way to deal with all of this would be to do a lot more at build-time. If we have any opportunity to do that, I think that is the best place to invest the energy but requiring another build plugin is probably a non-starter so may not be an option. If we just want to plug the current hole and ignore the DX & HTTP cache issues, we can take @dsyer's changes and publish a |
I don't think this is practical in some cases. Consider for example using https://github.com/springdoc/springdoc-openapi, which at least for our projects is actually the reason why the |
Thanks @dreis2211 for the use case. It might be possible in that case to have the generated file in the |
We don't do any templating - that's all on the library end. And by default the library is accessing stuff in a versionless fashion. But you can set the In all fairness. The library also provides ways already to build the OpenAPI json at build-time. But to the best of my knowledge this doesn't build the complete HTML which uses the The workaround posted by @dsyer in Spring Petclinic works for the Spring-Doc use-case as well and is what I'm mostly using these days to workaround the performance problems. Next to excluding |
Just for the sake of clarity: my proposal does not require a new jar (although that would make it easier to exclude the github dependency) - it's just a new utility API that you can use directly or through the old interface. A reasonable and conservative step in the right direction IMO would be just to include it in |
I was thinking a new artifact would be nice so we wouldn't have the transitive deps. |
|
Either is good. I think before we move forward we need to think more about the version lookup caching piece. Any thoughts on the best way to handle that? |
Hi any new thoughts about how to solve this? |
I think there is still a lot to be resolved around this and I haven't had time to solve any of it. :( |
For clarity sake, I don’t know why we can’t move forward with my patch. There is no caching issue in practice (IIRC Spring does all the work already, and probably other frameworks do), and classpath scanning could be eliminated with no impact on user code. |
There are still 4 unresolved issues:
|
Thanks James. IMO 1-3 are all nice to have - they are optional features that no-one has to use and we don't have to take them away just to support a different (also optional) utility. 4 is a solved problem AFAIK - Spring (and other frameworks) create cacheable resource URIs from the full path, but the developer never has to know the version (except to put the right thing on the classpath). This has been the case for many years, and all we want to do here is make the classpath resource resolution more efficient. So I still think the most pragmatic approach is to simply include the classpath utility stuff in the next release of webjars and move on to some of the other things if anyone cares deeply enough. It can be a separate jar file or it can go in the core, from a purely technical point of view it doesn't matter, but the github dependency should be optional either way. |
|
\2. The local cache doesn't have to be provided by webjars (libraries that use webjars could implement it also), but if you want one in a static \4. https://docs.spring.io/spring-framework/reference/web/webmvc/mvc-config/static-resources.html and https://docs.spring.io/spring-framework/reference/web/webmvc/mvc-config/static-resources.html (cache-busting explicitly mentioned there). |
\2. Totally open to the cache being external to WebJars Locator. I'm assuming Spring already has some mechanisms for in-memory caches. If you think we can get that into Spring then I'm down but we will need to consider both the HTTP request and the template usage. |
Spring has a CDN swapping as in "select the right CDN for the geographical origin of the request?" Is that anything to do with webjars? Maybe I misundertood. |
I've forked the changes: I cut out all the overlap with And released this for testing: As far as CDN stuff goes, in Play server-side templates you can do this:
Which resolves to the local server's path by default, but with this setting:
The path changes to (dependent on the WebJar type and version) in the classpath:
Let me know if this is headed in the right direction |
That's the same code I posted, so it gets my thumbs up. We should take the CDN topic elsewhere (another issue or something). |
Yup! Thank you. Let me know how integrating into Spring goes. For the CDN and caching topics, would you rather I file issues to facilitate discussion on a Spring repo or on the new lite repo? |
I don't mind. I don't really understand the requirement yet. We could do a "discussion" topic in the lite repo if you want. |
There's a discussion here spring-projects/spring-framework#27619 about how some common use cases do not require classpath scanning (specifically versionless URL path construction). Myself and @vpavic have both volunteered to contribute code here, but we need some guidance. One option would be to extract the "core core" into yet another Jar file (what would it be called?). Or we could make the classpath scanner an optional dependency here (use it to compile and test but not include it transitively by default). Or we could keep the dependency and simply make the classpath scanning lazy (only do it if it is needed).
UPDATE: added a third option.
The text was updated successfully, but these errors were encountered: