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

Re-implement callbacks in JS #97

Merged
merged 9 commits into from
Jul 5, 2024
Merged

Re-implement callbacks in JS #97

merged 9 commits into from
Jul 5, 2024

Conversation

khaledhosny
Copy link
Contributor

This paves the way to passing callback functions from JS to wasm and serves as an example.

@khaledhosny khaledhosny force-pushed the js-callbacks branch 2 times, most recently from 9c61b53 to 682a0cd Compare March 24, 2024 11:03
@khaledhosny khaledhosny force-pushed the js-callbacks branch 3 times, most recently from e2c0f36 to 3b60f9a Compare March 24, 2024 14:31
@khaledhosny khaledhosny linked an issue Mar 24, 2024 that may be closed by this pull request
@khaledhosny khaledhosny force-pushed the js-callbacks branch 2 times, most recently from 6655c17 to 18be250 Compare March 24, 2024 15:31
@khaledhosny khaledhosny changed the title Re-implement hbjs_glyph_svg in JS Re-implement callbacks in JS Mar 24, 2024
@behdad
Copy link
Member

behdad commented Mar 24, 2024

Any perf numbers?

@khaledhosny
Copy link
Contributor Author

There does not seem to be any measurable difference. Drawing the same glyph a million times:

old:

real	0m10.935s
user	0m10.871s
sys	0m0.242s

new:

real	0m10.954s
user	0m10.875s
sys	0m0.256s

Drawing all glyphs in NotoSans-Regular a 100 times:

old:

real	0m2.510s
user	0m2.509s
sys	0m0.073s

new:

real	0m2.522s
user	0m2.522s
sys	0m0.078s

@behdad
Copy link
Member

behdad commented Mar 24, 2024

That's quite impressive!

@chearon
Copy link
Contributor

chearon commented Mar 25, 2024

That's consistent with what I've found. I did a lot of profiling of C map, string, and array operations vs JS equivalents, and JS was at worst the same. String concatenation was always faster in JS. Though one thing nice about C is you don't have the garbage collector running, which can take seconds when you're working with huge amounts of memory.

This looks great! I did not know about Module.addFunction. I can make a PR for <canvas> support, it's not hard after this.


A little off-topic (shameless plug?) but I moved my harfbuzzjs efforts to here. One thing I did to get hbjs working in a production environment was put the glyph infos, positions and flags in a flattened Int32Array (so like an array of structs in C) instead of the JS objects this currently uses. That was key in getting good perf for shaping massive amounts of text. I also added OpenType functions used for font selection, and necessary feature/lookup functions for porting Firefox's glyph cache. Hopefully I can contribute that stuff back, but it was difficult to have WASM bundles for every dependency. TypeScript in particular would be really nice to have here.

@behdad
Copy link
Member

behdad commented Mar 25, 2024

Thanks for sharing. I don't think TypeScript is a problem.

graphicore added a commit to FontBureau/TypeRoof that referenced this pull request Mar 26, 2024
@khaledhosny
Copy link
Contributor Author

Any objection to merging this?

@behdad
Copy link
Member

behdad commented Jul 4, 2024

Go ahead!

@khaledhosny khaledhosny merged commit 058e09f into main Jul 5, 2024
1 check passed
@khaledhosny khaledhosny deleted the js-callbacks branch July 5, 2024 05:27
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.

shape() ignores supplied features
3 participants