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

Replace bytes.NewReader(stringToBytes(s)) with strings.NewReader(s) #610

Merged
merged 1 commit into from
Apr 8, 2020

Conversation

dolmen
Copy link
Contributor

@dolmen dolmen commented Apr 8, 2020

Description

Drop unnecessary uses of internal function stringToBytes.

Motivation and Context

stringToBytes uses package unsafe. stringToBytes is just a speed hack that kills portability. stringToBytes doesn't have a benchmark ensuring it helps for spped

This also reduces allocations as shown by benchmarks results.

How Has This Been Tested

go test
go test -bench B  -benchmem   # BenchmarkSetCellValue still fails like before my change

Benchmark before (66d0272):

goos: darwin
goarch: amd64
pkg: github.com/360EntSecGroup-Skylar/excelize/v2
BenchmarkOpenFile-4              	     566	   2753542 ns/op	  534112 B/op	    4476 allocs/op
BenchmarkWrite-4                 	       2	 630348442 ns/op	122600148 B/op	 1833689 allocs/op
BenchmarkAddPictureFromBytes-4   	   10000	    583967 ns/op	    6939 B/op	      38 allocs/op
BenchmarkRows-4                  	    2625	    477113 ns/op	  103223 B/op	    2304 allocs/op
BenchmarkStreamWriter-4          	    1809	    565083 ns/op	  133545 B/op	    4464 allocs/op

Benchmark after:

goos: darwin
goarch: amd64
pkg: github.com/360EntSecGroup-Skylar/excelize/v2
BenchmarkOpenFile-4              	     631	   1977463 ns/op	  533661 B/op	    4475 allocs/op
BenchmarkWrite-4                 	       2	 628304756 ns/op	122599896 B/op	 1833686 allocs/op
BenchmarkAddPictureFromBytes-4   	   10000	    562723 ns/op	    6939 B/op	      38 allocs/op
BenchmarkRows-4                  	    2395	    442256 ns/op	  103245 B/op	    2305 allocs/op
BenchmarkStreamWriter-4          	    1896	    731839 ns/op	  133538 B/op	    4463 allocs/op

Types of changes

  • Docs change / refactoring / dependency upgrade
  • 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

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

@xuri xuri merged commit 6e90fa6 into qax-os:master Apr 8, 2020
@xuri
Copy link
Member

xuri commented Apr 8, 2020

LGTM, thank you.

@xuri xuri added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Apr 9, 2020
@xuri xuri added this to Reviewer approved in v2.2.0 Apr 10, 2020
@xuri xuri moved this from Reviewer approved to Performance in v2.2.0 Apr 23, 2020
nullfy pushed a commit to nullfy/excelize that referenced this pull request Oct 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
No open projects
v2.2.0
  
Performance
Development

Successfully merging this pull request may close these issues.

None yet

2 participants