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

Performance regression in isPlainObject utility #804

Closed
1 of 3 tasks
benelliott opened this issue May 26, 2021 · 1 comment · Fixed by #805
Closed
1 of 3 tasks

Performance regression in isPlainObject utility #804

benelliott opened this issue May 26, 2021 · 1 comment · Fixed by #805
Labels

Comments

@benelliott
Copy link
Contributor

🐛 Bug Report

The changes to isPlainObject introduced in #767 added a more comprehensive check that worked for objects across iframes which relies on Function.toString:

	const Ctor =
		Object.hasOwnProperty.call(proto, "constructor") && proto.constructor
	return (
		typeof Ctor == "function" &&
		Function.toString.call(Ctor) === objectCtorString
	)

This more robust check is quite expensive for the common case where the object instance comes from the same frame and a simpler equality check would suffice.

I will submit a PR to remedy this.

Link to repro

N/A (Perf)

To Reproduce

N/A (Perf)

Observed behavior

In our app we invoke immer.applyPatches multiple times per second based on WebSocket events. The calls to Function.toString have a noticeable performance impact on our app.

Expected behavior

The utility method should not have a substantial impact on performance.

Environment

We only accept bug reports against the latest Immer version.

  • Immer version:
  • I filed this report against the latest version of Immer
  • Occurs with setUseProxies(true)
  • Occurs with setUseProxies(false) (ES5 only)
@mweststrate
Copy link
Collaborator

🎉 This issue has been resolved in version 9.0.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants