Personal tools

XPCOM/Bootstrap

From MozillaWiki

Jump to: navigation, search

The XPCOM bootstrap process is overly complicated and time-consuming. I'd like to take the following actions to simplify it:

This work is complete, NS_InitEmbedding has been removed.

State Management

The XPCOM startup and shutdown sequences are very state-sensitive: you must release objects in certain orders, and end threads by a certain point, etc. This is currently managed entirely through observers... in many cases it would be simpler and better to have a global XPCOM state:

enum XPCOMState {
  NS_XPCOM_UNINITIALIZED,
  NS_XPCOM_BEFOREPROFILE,
  NS_XPCOM_PROFILESTARTED,
  NS_XPCOM_EVENTLOOP,
  NS_XPCOM_UI_ATTEMPT_QUIT,
  NS_XPCOM_UI_SHUTDOWN,
  NS_XPCOM_SHUTTING_DOWN,
  NS_XPCOM_SHUTTING_DOWN_LOADERS,
  NS_XPCOM_SHUTDOWN
}

State transitions would be managed entirely by the bootstrap code, and code throughout the tree would be able to do simple sanity-checks, e.g.:

  • don't spin the event loop except during certain states
  • don't create windows, or reflow, or fire any DOM events during shutdown
  • don't fire DNS resolution events after XPCOM has started shutting down

Registration

Move component registration to chrome.manifest.

Component registration currently requires loading all our modules and asking each one programmatically which components it implements. This is time-consuming and requires XPCOM to restart after it has been completed.

The only two things you should need to do during registration is register contractIDs/CIDs and add category entries.

I'd like to move component registration into the chrome.manifest files to be declarative lines:

component <CID> <file>
contract <contractid> <CID>
category <category> <entry> <value>

For example, to register a single CID and contract:

component 550e8400-e29b-41d4-a716-446655440000 components/MyComponent.js
contract @foo.bar/my-component;1 550e8400-e29b-41d4-a716-446655440000

Potential pitfalls: currently components that fail to load (for instance because system libraries are not available) will not register at all. With declarative registration they will now be registered, but will fail to load.