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: optimize Buffer.from("base64") for forgiving-base64 conforming input #24346

Merged
merged 1 commit into from
Jun 26, 2024

Conversation

littledivy
Copy link
Member

@littledivy littledivy commented Jun 26, 2024

Don't try to clean the input unless decoding fails at first. A ~3x improvement for forgiving-base64 conforming input.

$ target/release/deno run  -A ./bench.mjs
593.3049169
$ deno run -A ./bench.mjs
1912.209888
$ node bench.mjs
989.406209
import { Buffer } from "node:buffer";

const buffer = Buffer.alloc(1024 * 10, "latin1");
const input = buffer.toString("base64");
const start = performance.now();
for (let i = 0; i < 100000; i++) {
	Buffer.from(input, "base64");
}

console.log(performance.now() - start);

Ref #24323

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

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

Nice work!

@littledivy littledivy merged commit 2549e51 into denoland:main Jun 26, 2024
17 checks passed
@littledivy littledivy deleted the perf_buffer_from_base64_string branch June 26, 2024 13:25
sbmsr pushed a commit to sbmsr/deno-1 that referenced this pull request Jul 2, 2024
zebreus pushed a commit to zebreus/deno that referenced this pull request Jul 8, 2024
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