Skip to content

perf: reduce ObjectAssign overhead#5698

Merged
D-Sketon merged 2 commits intohexojs:masterfrom
D-Sketon:perf/8.0.0-6
Oct 3, 2025
Merged

perf: reduce ObjectAssign overhead#5698
D-Sketon merged 2 commits intohexojs:masterfrom
D-Sketon:perf/8.0.0-6

Conversation

@D-Sketon
Copy link
Member

@D-Sketon D-Sketon commented Oct 2, 2025

What does it do?

Interestingly, just modifying this single line can significantly reduce the overhead of ObjectAssign.

Screenshots

8x hexo-many-posts + hexo-theme-reimu

before
{5CD5CAD9-97B6-4AE7-9DC7-CBD69F5FE496}

after
{DB9C014C-0B5B-4420-90B7-A790DB641960}

Pull request tasks

  • Add test cases for the changes.
  • Passed the CI test.

@github-actions
Copy link

github-actions bot commented Oct 2, 2025

How to test

git clone -b perf/8.0.0-6 https://github.com/D-Sketon/hexo.git
cd hexo
npm install
npm test

@coveralls
Copy link

coveralls commented Oct 2, 2025

Pull Request Test Coverage Report for Build 18185497716

Details

  • 1 of 1 (100.0%) changed or added relevant line in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 99.526%

Totals Coverage Status
Change from base Build 18138329632: 0.0%
Covered Lines: 9864
Relevant Lines: 9911

💛 - Coveralls

Copy link
Member

@SukkaW SukkaW left a comment

Choose a reason for hiding this comment

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

Basically, Object.assign is just reading and assigning properties and values one by one, that's why the following use case of Object.assign also works:

Object.assign(htmlElement.style, { fontSize: '12px', color: 'navy' });
// This is basically the same as
htmlElement.style.fontSize = '12px';
htmlElement.style.color = 'navy';

Object.assign(function() {}, { extraPropOnFunction });
// This is basically the same as
(function() {}).extraPropOnFunction = extraPropOnFunction;

Thus, Object.assign on a plain object will also face the same Monomorphism JIT issue of V8. If we predefine the shape of the object, V8 will have to de-optimize later. But if we don't define the shape, V8 will determine the shape itself.

@D-Sketon D-Sketon merged commit 7a226b8 into hexojs:master Oct 3, 2025
23 checks passed
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.

3 participants