javadependency-injectiongwtgwt-platform

Java GWT dependency injection


We now have in our project a class which has 1000 lines of bindPresenter(...) in its only method that starts when app starts. I'm worried about performance: can such injection slow down application? Am i right that it is not lazy injection and all presentors are creating with all their dependencies at the start of application?

We used profiler and it seems like injection really slow down start, but we are not sure.


Solution

  • I doubt that your 1000 of bind statements slow down your application's load time. From GWTP's Presenter docs:

    Each presenter is associated to a Proxy which is responsible for listening to the various events of interest for this presenter. This makes it possible to lazily instantiate the presenter and use GWT code splitting.

    Since Presenters are lazy-instantiated, your slow start might be caused by somthing else.

    One thing that might slow down your load time is if you do heavy PresenterWidget injection, without using Gin's Providers:

    @Inject
    ParentPresenter(
      SomePresenterWidget a, 
      SomePresenterWidget b) {
      // ...
    }
    

    Injecting many PresenterWidgets like this requires to build the PresenterWidgets up front, which might cause loading slowdowns. You could use Providers to lazy-load PresenterWidgets:

    @Inject
    ParentPresenter(
      Provider<SomePresenterWidget> a, 
      Provider<SomePresenterWidget> b) {
      // ...
    }
    

    and only instantiate the PresenterWidgets using provider.get() when needed.