Skip to content

perf(nuxt): avoid duplicate iterations over layers#24730

Merged
danielroe merged 4 commits intonuxt:mainfrom
GalacticHypernova:patch-14
Dec 14, 2023
Merged

perf(nuxt): avoid duplicate iterations over layers#24730
danielroe merged 4 commits intonuxt:mainfrom
GalacticHypernova:patch-14

Conversation

@GalacticHypernova
Copy link
Copy Markdown
Contributor

@GalacticHypernova GalacticHypernova commented Dec 13, 2023

🔗 Linked issue

❓ Type of change

  • 📖 Documentation (updates to the documentation, readme or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

This PR saves the mapped configs (and their reversed counterpart) to avoid the repetitive operations when generating the app, resulting in a ~81.7% increase in performance.
Benchmark results (offline, from host PC):

const nuxt={
    options:{
        _layers:[
            {config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true},{config:true}
        ]
    }
}
console.time("regular")
for (let index = 0; index < 100000; index++) {
    for(const config of nuxt.options._layers.map(layer => layer.config)){

    }
}
console.timeEnd("regular")
const layerConfigs=nuxt.options._layers.map(layer => layer.config)
console.time("PR")
for (let index = 0; index < 100000; index++) {
    for(const config of layerConfigs){}
}
console.timeEnd("PR")

image

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@bolt-new-by-stackblitz
Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@github-actions github-actions bot added the 3.x label Dec 13, 2023
@GalacticHypernova GalacticHypernova changed the title perf(nuxt): avoid duplicate array mappings perf(nuxt): avoid duplicate array mappings and reverses Dec 13, 2023
@GalacticHypernova GalacticHypernova changed the title perf(nuxt): avoid duplicate array mappings and reverses perf(nuxt): avoid duplicate array mappings Dec 13, 2023
@GalacticHypernova
Copy link
Copy Markdown
Contributor Author

I have reverted the reverse update (no pun intended) for the time being.

@GalacticHypernova GalacticHypernova changed the title perf(nuxt): avoid duplicate array mappings perf(nuxt): avoid duplicate array mappings and reverses Dec 13, 2023
@GalacticHypernova
Copy link
Copy Markdown
Contributor Author

Turns out all I needed to do was combine the 2 approaches, that way we still save the time of the second reverse,

@danielroe danielroe changed the title perf(nuxt): avoid duplicate array mappings and reverses perf(nuxt): avoid duplicate iterations over layers Dec 14, 2023
@danielroe danielroe merged commit eff6843 into nuxt:main Dec 14, 2023
@github-actions github-actions bot mentioned this pull request Dec 14, 2023
@GalacticHypernova GalacticHypernova deleted the patch-14 branch December 15, 2023 14:35
@GalacticHypernova GalacticHypernova restored the patch-14 branch December 15, 2023 14:35
@GalacticHypernova GalacticHypernova deleted the patch-14 branch December 15, 2023 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants