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

Issue 1455 pre generate strings for months #1456

Merged

Conversation

nathj07
Copy link
Contributor

@nathj07 nathj07 commented Jan 24, 2023

On reviewing the code I was focussed on I figured I could add a couple of slices and then simplify some the code around getting month name abbreviations. At this point I thought I'd get some input, in case you want to go a different way? Or, if you like this approach if you want to implement for all languages I could go ahead and do that.

I have also removed some of the unnecessary string([]rune(... casts that were in place. Doing this prevents these tings from escaping to the heap

Either way, it seemed worth getting some feedback before going any further.

Description

As an example of the proposed change I've introduced a couple of month abbreviation slices and shown how these could be used to simplify their corresponding functions. The existing tests already cover this code and continue to pass.

Related Issue

issue-1455

Motivation and Context

This is an attempt to reduce the memory needed by these language functions that have string concatenation involved.

How Has This Been Tested

The existing tests cover this code and they continue to pass. I do not think extra tests are needed here. Since adding these changes I can see, via go build -gcflags="-m -l", that there is less that escapes to the heap.

Types of changes

  • Docs change / refactoring / dependency upgrade
  • [ x] Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • [x ] My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • [ x] I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • [ x] All new and existing tests passed.

On reviewing the code I was focussed on I figured I could add a couple of slices
and then simplify some the code around getting month name abbreviations. At this point
I thought I'd get some input, in case you want to go a different way? Or, if you like this
approach if you want to implement for all languages I could go ahead and do that.

Either way, it seemed worth getting some feedback before going any further.
There were finctions where we do not need to convert to rune and then to string.

Removing these casts prevents things escaping to the heap
@xuri xuri added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Jan 24, 2023
@nathj07
Copy link
Contributor Author

nathj07 commented Jan 24, 2023

@xuri I spotted some commented out code I'd left behind. I tidied this up in the most recent push. Hopefully this is looking good now, let me know what you think

@codecov-commenter
Copy link

codecov-commenter commented Jan 25, 2023

Codecov Report

Merging #1456 (5b13abb) into master (5429f13) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #1456   +/-   ##
=======================================
  Coverage   98.61%   98.61%           
=======================================
  Files          31       31           
  Lines       24015    24026   +11     
=======================================
+ Hits        23682    23693   +11     
  Misses        220      220           
  Partials      113      113           
Flag Coverage Δ
unittests 98.61% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
numfmt.go 100.00% <100.00%> (ø)
date.go 100.00% <0.00%> (ø)
sheet.go 100.00% <0.00%> (ø)
calc.go 99.03% <0.00%> (+<0.01%) ⬆️
excelize.go 99.68% <0.00%> (+<0.01%) ⬆️
lib.go 98.26% <0.00%> (+0.01%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Member

@xuri xuri left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution. This is a good way to improve performance, I think we can implement it for all languages.

@xuri xuri merged commit 1ab7a99 into qax-os:master Jan 25, 2023
@nathj07 nathj07 deleted the issue-1455-pre-generate-strings-for-months branch January 25, 2023 07:15
xuri pushed a commit to JDavidVR/excelize that referenced this pull request Jul 11, 2023
…ormat (qax-os#1456)

- Reducing string concatenation and string conversion between rune string data types

Co-authored-by: Nathan Davies <[email protected]>
jenbonzhang pushed a commit to jenbonzhang/excelize that referenced this pull request Oct 22, 2023
…ormat (qax-os#1456)

- Reducing string concatenation and string conversion between rune string data types

Co-authored-by: Nathan Davies <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants