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

perf(marshal): Replace more XS-expensive string operations #2005

Merged
merged 1 commit into from
Jan 25, 2024

Conversation

gibson042
Copy link
Contributor

@gibson042 gibson042 commented Jan 25, 2024

Most notably, prefer charAt(0) === ch over startsWith(ch).

$ esbench --eshost-option '-h *XS' --init '
const c50 = "I am the *very* model of a modern major general.\n\n";
const c500 = Array(10).fill(c50).join("");
const c5k = Array(100).fill(c50).join("");
const c50k = Array(1000).fill(c50).join("");
' '' '{                                     
  "c50.startsWith(ch)": `result = c50.startsWith("I");`,
  "c500.startsWith(ch)": `result = c500.startsWith("I");`,
  "c5k.startsWith(ch)": `result = c5k.startsWith("I");`,
  "c50k.startsWith(ch)": `result = c50k.startsWith("I");`,
  "c50[0]": `result = c50[0] === "I";`,
  "c500[0]": `result = c500[0] === "I";`,
  "c5k[0]": `result = c5k[0] === "I";`,
  "c50k[0]": `result = c50k[0] === "I";`,
  "c50.charAt(0)": `result = c50.charAt(0) === "I";`,
  "c500.charAt(0)": `result = c500.charAt(0) === "I";`,
  "c5k.charAt(0)": `result = c5k.charAt(0) === "I";`,
  "c50k.charAt(0)": `result = c50k.charAt(0) === "I";`,
}'
#### Moddable XS
c50.startsWith(ch): 9.17 ops/ms
c500.startsWith(ch): 5.03 ops/ms
c5k.startsWith(ch): 1.84 ops/ms
c50k.startsWith(ch): 0.22 ops/ms
c50[0]: 8.20 ops/ms
c500[0]: 6.06 ops/ms
c5k[0]: 1.85 ops/ms
c50k[0]: 0.24 ops/ms
c50.charAt(0): 8.55 ops/ms
c500.charAt(0): 8.06 ops/ms
c5k.charAt(0): 9.09 ops/ms
c50k.charAt(0): 8.70 ops/ms

Ref #1982
Ref #2001

Security Considerations

n/a

Scaling Considerations

As stated on the tin.

Documentation Considerations

n/a

Testing Considerations

n/a

Compatibility Considerations

n/a

Upgrade Considerations

Some error messages are affected.

Most notably, prefer `charAt(0) === ch` over `startsWith(ch)`.

Ref #1982
Ref #2001
Copy link
Contributor

@erights erights 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!

@@ -182,37 +182,38 @@ const encodeBigInt = n => {
}
};

const rBigIntPayload = /([0-9]+)(:([0-9]+$|)|)/s;
Copy link
Contributor

Choose a reason for hiding this comment

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

Good. Consolidating the regexp makes this much more declarative and readable. Nice!

@erights
Copy link
Contributor

erights commented Jan 25, 2024

Please include enough info so others would know how to rerun your timing tests.

@gibson042 gibson042 merged commit 3cf477a into master Jan 25, 2024
14 checks passed
@gibson042 gibson042 deleted the gibson-2024-01-passable-perf-2 branch January 25, 2024 05:31
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