Skip to content

feat(plugins): improve plugins load#639

Merged
ogustavo-pereira merged 4 commits into
masterfrom
fix-redundant-plugins-load
Dec 30, 2022
Merged

feat(plugins): improve plugins load#639
ogustavo-pereira merged 4 commits into
masterfrom
fix-redundant-plugins-load

Conversation

@dubisdev
Copy link
Copy Markdown
Contributor

@dubisdev dubisdev commented Dec 9, 2022

This PR should make Cerebro more performant.

The idea of the double renderer process was to make the second take care of the heavier tasks.
However, it was doing too much work by duplicating tasks that are already done in the main renderer.

The loading of plugins and the control over the addition of new plugins was being done in both renderers, which led to an unnecessary waste of resources (duplicated chockidar instances watching folders, double loading of plugins)

image

With this PR, we make the second renderer do what it is supposed to do: take care of the async loads of plugins

image

ref #118

Copy link
Copy Markdown
Member

@ogustavo-pereira ogustavo-pereira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A big pr will help the project a lot

Comment thread app/plugins/index.js Outdated
import getExternalPlugins from './externalPlugins'

export default Object.assign(externalPlugins, core)
class PluginsService {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Migrate to functonal component

Comment thread app/plugins/index.js Outdated
}
}

export default new PluginsService()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export default new PluginsService()
export { getAllPlugins, getExternalPlugins, getCorePlugins }

Comment thread app/plugins/externalPlugins.js Outdated
const plugins = {}

const pluginsWatcher = chokidar.watch(modulesDirectory, { depth: 1 })
function setupPluginsWatcher() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use

Suggested change
function setupPluginsWatcher() {
(() => {...})()

global.React = React
global.ReactDOM = ReactDOM
global.isBackground = true

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const corePlugins = getCorePlugins()

Comment thread app/background/background.js Outdated

try {
const plugin = plugins[name] || window.require(`${modulesDirectory}/${name}`)
const plugin = PluginsService.getCorePlugins()[name] || window.require(`${modulesDirectory}/${name}`)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    const plugin = corePlugins[name] || window.require(`${modulesDirectory}/${name}`)

Comment thread app/plugins/core/autocomplete/index.js Outdated
map(pluginToResult(actions)),
display
)(plugins)
)(PluginsService.getAllPlugins())
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

)(getAllPlugins())

Comment thread app/lib/initializePlugins.js Outdated
const plugin = plugins[name]
if (plugin.onMessage) plugin.onMessage(data)
})
listenToAsyncMessages()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this function is not necessary

Comment thread app/lib/initializePlugins.js Outdated
})
listenToAsyncMessages()

const allPlugins = PluginsService.getAllPlugins()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  const allPlugins = PluginsService.getAllPlugins()
  
  on('plugin.message', ({ name, data }) => {
    const plugin = allPlugins[name]
    if (plugin.onMessage) plugin.onMessage(data)
  })

@dubisdev dubisdev removed their assignment Dec 13, 2022
@ogustavo-pereira ogustavo-pereira changed the title fix: delete redundant plugins load feat(plugins): improve plugins load Dec 30, 2022
@ogustavo-pereira ogustavo-pereira force-pushed the fix-redundant-plugins-load branch from 4907c74 to d3f0247 Compare December 30, 2022 01:26
@ogustavo-pereira ogustavo-pereira merged commit 86cd68c into master Dec 30, 2022
@ogustavo-pereira ogustavo-pereira deleted the fix-redundant-plugins-load branch December 30, 2022 01:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants