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

Improve extension creation runtime #6958

Merged

Conversation

DZakh
Copy link
Contributor

@DZakh DZakh commented Aug 17, 2024

Also, removed /1 for RE_EXN_ID created the first time

@cknitt
Copy link
Member

cknitt commented Aug 17, 2024

What's the advantage of using Dict vs. Map?

@DZakh
Copy link
Contributor Author

DZakh commented Aug 17, 2024

What's the advantage of using Dict vs. Map?

It's faster and simpler

@cknitt
Copy link
Member

cknitt commented Aug 18, 2024

Is it really faster?

This article here seems to suggest otherwise:
https://rehmat-sayany.medium.com/using-map-over-objects-in-javascript-a-performance-benchmark-ff2f351851ed

Typical applications should not create that many different exception types anyway though, so it probably doesn't matter much?

@DZakh
Copy link
Contributor Author

DZakh commented Aug 18, 2024

Is it really faster?

This article here seems to suggest otherwise: https://rehmat-sayany.medium.com/using-map-over-objects-in-javascript-a-performance-benchmark-ff2f351851ed

Typical applications should not create that many different exception types anyway though, so it probably doesn't matter much?

I don't know about the benchmark, but according to my knowledge {} may run in different optimisation modes depending on the number of keys and can drastically slow down when there are more than 20 or something like this. But Map uses the same representation under the hood which is even more complex, since it needs to support objects as keys and many iteration methods + every set and get is a function call.

And in the benchmark you can see that it's 20 times slower:

https://jsbenchmark.com/#eyJjYXNlcyI6W3siaWQiOiJzbFZZeUNzc2dKUG1VREE5RDdieEQiLCJjb2RlIjoiREFUQS5tYXAuc2V0KFwiZm9vXCIsIDEpXG5EQVRBLm1hcC5zZXQoXCJmb29cIiwgMilcbkRBVEEubWFwLnNldChcImJhclwiLCAxKVxuREFUQS5tYXAuc2V0KFwiYmF6XCIsIERBVEEubWFwLmdldChcImZvb1wiKSkiLCJuYW1lIjoibWFwIiwiZGVwZW5kZW5jaWVzIjpbXX0seyJpZCI6IkloVjEyMjJzekxVa2wzazZQanc1ZCIsImNvZGUiOiJEQVRBLmRpY3RbXCJmb29cIl0gPSAxXG5EQVRBLmRpY3RbXCJmb29cIl0gPSAyXG5EQVRBLmRpY3RbXCJiYXJcIl0gPSAxXG5EQVRBLmRpY3RbXCJiYXpcIl0gPSBEQVRBLmRpY3RbXCJmb29cIl0iLCJuYW1lIjoiZGljdCIsImRlcGVuZGVuY2llcyI6W119XSwiY29uZmlnIjp7Im5hbWUiOiJCYXNpYyBleGFtcGxlIiwicGFyYWxsZWwiOnRydWUsImdsb2JhbFRlc3RDb25maWciOnsiZGVwZW5kZW5jaWVzIjpbXX0sImRhdGFDb2RlIjoicmV0dXJuIHtcbiAgbWFwOiBuZXcgTWFwKCksXG4gIGRpY3Q6IHt9XG59In19

@DZakh
Copy link
Contributor Author

DZakh commented Aug 18, 2024

image

@cknitt
Copy link
Member

cknitt commented Aug 20, 2024

And in the benchmark you can see that it's 20 times slower:

😱 Then that makes a lot of sense of course. Not sure what the guy in that medium article benchmarked with. This jsbenchmark.com is nice BTW.

@cristianoc Are the changes fine with you, too?

Co-authored-by: Christoph Knittel <christoph@knittel.cc>
Copy link
Member

@cknitt cknitt left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks a lot!

@cknitt cknitt merged commit 5e6c891 into rescript-lang:master Aug 21, 2024
20 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.

2 participants