Load modules in parallel

Topics: Prism v4 - WPF 4
Jan 11, 2013 at 8:23 PM

Hi,

I am implementing a composite application that needs to load most of the modules at startup (all of them have data to show in the view at startup) and I am afraid that if I use the existing module loaders it will take several minutes to load of all them. I was considering overriding the method LoadModulesThatAreReadyForLoad() in ModuleManager. Would it be the right way to go?  Can you provide tips or examples on how to customize module loading to load each module in its own thread in parallel? 

Thanks,

Developer
Jan 14, 2013 at 8:11 PM

Hi,

Based on my understanding, the process of loading modules can be divided in two separate steps: loading the assembly containing the module and initializing the module.

For the first step, I don't believe using threads or similar approaches would affect the loading time of an assembly, as the threads would have to wait for the disk to complete their requests to read the corresponding files.

As for the second step, it might be possible to modify the LoadModulesThatAreReadyForLoad method to load each module in a separate thread (for example, by executing the " this.InitializeModule(moduleInfo); " line inside the threads.) I don't know if such approach would report any performance improvements when initializing modules, but you will have to consider how to manage the dependencies between modules (modules that are related by a dependency should not be initialized concurrently) and how to check when a module has completed it's initializing process.

Also, if your modules have a complex initialization logic, you could create threads inside the Initialize method of the module. However, in this case you will need to make sure that all threads have finished their work before returning from the Initialize method (if not, the module could be declared as Initialized while some of its threads could still be working in the background.)

In my opinion, you could first develop the modules and check how much they take to load before searching how to improve their loading time, as it might be possible for the modules to load fast enough without requiring any modification in the initialization logic.

On the other hand, if you are experiencing a poor performance when initializing modules, it would be helpful if you could provide us with more information about what initialization logic you have in your modules, so that we could help you improve its initialization time, as its possible that some of its logic could be moved to other components of the module.

Regards,

Damian Cherubini
http://blogs.southworks.net/dcherubini