We're overriding the dispatch.Http so that we can give it different configuration (request/connection timeouts, user agents, etc). However, we noticed that we were generating many threads from many different netty NioWorkers. Looking into it more, it turns out each AsyncHttpClientConfig.Builder spawns a thread pool of these. And looking at our heap dumps, we found that there are many AsyncHttpClientConfig.Builders within the heap.
Anyways, we found out that due to the scala trait initialization order, the scalaxb.DispatchHttpClient was always initializing a new Http even though we were overriding it. So by making it a lazy val, we can safely override it without worrying about it getting initialized.
using lazy val http for async so can be overridden
Could you add a comment to the effect in the code since the change is too subtle and I don't want that to be rolled back by mistake in the future. It could be something like:
// Keep it lazy. See https://github.com/eed3si9n/scalaxb/pull/279
Adding note re http laziness in async templates