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

Refactor copying query result to clipboard #25152

Merged

Conversation

serhat359
Copy link
Contributor

@serhat359 serhat359 commented Dec 27, 2023

Closes the issue #24901
Makes copying table result to clipboard faster by using a StringBuilder (JS/TS implementation).

I've locally tested before and after versions of the function with different inputs to make sure the new function behaves the same as before.

You can see the performance results comparing before and after below. Each data row contains 4 columns ('foo', 'bar', 'baz', row index). SkipNewLine means the variable shouldSkipNewLineAfterTrailingLineBreak config setting in the code.

Row Count SkipNewLine Before (millis) After (millis)
10 true 0.0029 0.0013
10 false 0.0021 0.0013
100 true 0.0115 0.0051
100 false 0.0115 0.0051
1000 true 0.8231 0.0499
1000 false 0.7725 0.0449
10000 true 238.3471 0.5279
10000 false 238.4657 0.4919
20000 true 1448.4772 1.1383
20000 false 1449.1719 1.1553
50000 true 9376.8284 3.0909
50000 false 9385.3372 3.1018

@serhat359
Copy link
Contributor Author

@microsoft-github-policy-service agree

@coveralls
Copy link

Pull Request Test Coverage Report for Build 7342499286

  • 0 of 13 (0.0%) changed or added relevant lines in 1 file are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-0.002%) to 41.607%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/sql/workbench/services/query/common/gridDataProvider.ts 0 13 0.0%
Files with Coverage Reduction New Missed Lines %
src/sql/workbench/services/connection/browser/connectionDialogWidget.ts 1 73.44%
Totals Coverage Status
Change from base Build 7292826141: -0.002%
Covered Lines: 30839
Relevant Lines: 69426

💛 - Coveralls

Copy link
Contributor

@Charles-Gagnon Charles-Gagnon left a comment

Choose a reason for hiding this comment

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

I'm pretty surprised that using reduce has that much of an impact. What kind of timing improvements were you seeing? i.e. with the same result data what was the time to copy with the original implementation vs what you have now?

@@ -133,7 +133,7 @@ export async function copySelectionToClipboard(clipboardService: IClipboardServi
const getMessageText = (): string => {
return nls.localize('gridDataProvider.loadingRowsInProgress', "Loading the rows to be copied ({0}/{1})...", processedRows, rowCount);
};
let resultString = '';
let headerString = '';
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Instead of making a whole separate var and copying that into the array you create below I'd suggest just creating the array here and push the header to it directly on line 145.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I guess I could do that but I wanted the logic of string-join to be separated from the logic of creating the data rows.

@alanrenmsft
Copy link
Contributor

@serhat359 thanks for the PR, could you please update the PR description to include the perf improvements? e.g.

rows, columns, time taken before, time taken after

@serhat359
Copy link
Contributor Author

@alanrenmsft I added a table to the description that shows the performance improvements.

@alanrenmsft
Copy link
Contributor

@serhat359 thanks!

@serhat359
Copy link
Contributor Author

When would this fix be merged to the main branch?

@cheenamalhotra cheenamalhotra merged commit d0e9e30 into microsoft:main Jan 15, 2024
8 checks passed
@serhat359 serhat359 deleted the make-copy-to-clipboard-faster branch January 20, 2024 11:41
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.

None yet

5 participants