Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(plugins): improve plugins load #639

Merged
merged 4 commits into from
Dec 30, 2022

Conversation

dubisdev
Copy link
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
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


export default Object.assign(externalPlugins, core)
class PluginsService {
Copy link
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

}
}

export default new PluginsService()
Copy link
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 }

@@ -50,59 +50,64 @@ const getPluginName = (pluginPath) => {

const plugins = {}

const pluginsWatcher = chokidar.watch(modulesDirectory, { depth: 1 })
function setupPluginsWatcher() {
Copy link
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
Member

Choose a reason for hiding this comment

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

const corePlugins = getCorePlugins()


on('initializePluginAsync', ({ name }) => {
console.group(`Initialize async plugin ${name}`)

try {
const plugin = plugins[name] || window.require(`${modulesDirectory}/${name}`)
const plugin = PluginsService.getCorePlugins()[name] || window.require(`${modulesDirectory}/${name}`)
Copy link
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}`)

@@ -32,6 +32,6 @@ const fn = ({ term, display, actions }) => flow(
filter(notMatch(term)),
map(pluginToResult(actions)),
display
)(plugins)
)(PluginsService.getAllPlugins())
Copy link
Member

Choose a reason for hiding this comment

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

)(getAllPlugins())

const plugin = plugins[name]
if (plugin.onMessage) plugin.onMessage(data)
})
listenToAsyncMessages()
Copy link
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

})
listenToAsyncMessages()

const allPlugins = PluginsService.getAllPlugins()
Copy link
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 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