Skip to content

Optimize, simplify FromChunkedBase64String method#1868

Merged
twsouthwick merged 2 commits intodotnet:mainfrom
QuocDatHoang:flatopc-extensions/optimize-fromChunkBase64String
Mar 10, 2025
Merged

Optimize, simplify FromChunkedBase64String method#1868
twsouthwick merged 2 commits intodotnet:mainfrom
QuocDatHoang:flatopc-extensions/optimize-fromChunkBase64String

Conversation

@QuocDatHoang
Copy link
Copy Markdown
Contributor

This update optimizes and simplifies the FromChunkedBase64String method, improving both performance and memory efficiency.

Implementation Details

Removed unnecessary manual handling of \r and \n, as Convert.FromBase64String already handles these characters automatically.
Eliminated Where() and ToArray() operations, significantly reducing memory allocations and improving execution efficiency.

Benchmark Results

Performance: ~2.4x speed improvement
Memory Usage: ~70% reduction

image

@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 6, 2025

Test Results

    70 files      70 suites   1h 7m 48s ⏱️
 2 041 tests  2 038 ✅  3 💤 0 ❌
32 418 runs  32 382 ✅ 36 💤 0 ❌

Results for commit bee9325.

♻️ This comment has been updated with latest results.

return Cached.Array<byte>();
}

var base64CharArray = chunkedBase64String.Where(c => c is not '\r' and not '\n').ToArray();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you sure the chunkedBase64String much not include the \r or \n char?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hi @lindexi. Yes, I am sure \r and \n will be removed automatically.
This is source code of the method in dotnet runtime:
image

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@QuocDatHoang Thank you very much.

Copy link
Copy Markdown
Member

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

@twsouthwick twsouthwick merged commit 0109970 into dotnet:main Mar 10, 2025
22 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.

5 participants