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

Replaced concat with push for better performance per #682 #683

Merged
merged 1 commit into from
Mar 22, 2024

Conversation

Balearica
Copy link
Contributor

Description

Replaces instances of d = d.concat(...) with push within cmap functions for improved performance per #682. Should not impact results. Conceptually speaking, this is almost identical to #513.

Additionally, t.segments.sort was being run every time a new element was added within a loop; I edited to only run once after all elements are inserted.

Motivation and Context

See #682. In short, the performance of font.toArrayBuffer() can be poor, including >30+ second runtimes for certain large fonts. This PR fixes that.

On my system (Chrome, Windows 10), this PR reduces the runtime for writing NotoSansSC from 36 seconds to 8 seconds (78% reduction), and reduces the runtime for NotoSerifSC from 33 seconds to 8 seconds (76% reduction).

How Has This Been Tested?

The unit tests pass and I am using a version with these changes in my project. Additionally, the change is conceptually simple and narrow in scope.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I did npm run test and all tests passed green (including code styling checks).
  • I have added tests to cover my changes.
  • My change requires a change to the documentation.
  • I have updated the README accordingly.
  • I have read the CONTRIBUTING document.

@Connum
Copy link
Contributor

Connum commented Mar 22, 2024

Could you add a performance test by measuring the time it takes to run toArrayBuffer() and making sure it's below a certain threshold that it was above without the change?

@Connum
Copy link
Contributor

Connum commented Mar 22, 2024

I will add a test and a new local rule for banning concat(). But I can clearly confirm the performance improvement! I'll review and merge this soon.

Connum added a commit to Connum/opentype.js-next that referenced this pull request Mar 22, 2024
Copy link
Contributor

@Connum Connum left a comment

Choose a reason for hiding this comment

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

Looking good!

src/tables/cmap.js Show resolved Hide resolved
@Connum Connum merged commit fda7e3b into opentypejs:master Mar 22, 2024
1 check passed
@Connum Connum added this to the Release 2.0.0 milestone Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants