jwt icon indicating copy to clipboard operation
jwt copied to clipboard

no need for string slice and call to strings.join

Open moneszarrugh opened this issue 3 years ago • 3 comments

this cleans up the code a bit and avoids unnecessary memory allocations

moneszarrugh avatar Oct 22 '21 21:10 moneszarrugh

and avoids unnecessary memory allocations

Would it be possible to add a benchmark to demonstrate that change indeed reduces allocations?

AlexanderYastrebov avatar Nov 07 '21 21:11 AlexanderYastrebov

@moneszarrugh @AlexanderYastrebov There is an example on #34 (which is stale but I came back to take a look at and should be merged in the meantime before this one goes to the same code)

lggomez avatar Jan 16 '22 20:01 lggomez

@moneszarrugh @AlexanderYastrebov There is an example on #34 (which is stale but I came back to take a look at and should be merged in the meantime before this one goes to the same code)

Sorry for keeping this stale, as I have no freetime to benchmark and test it. If anyone is interested in adding these feel free to do it.

moneszarrugh avatar Jan 16 '22 21:01 moneszarrugh

@moneszarrugh @AlexanderYastrebov There is an example on #34 (which is stale but I came back to take a look at and should be merged in the meantime before this one goes to the same code)

Sorry for keeping this stale, as I have no freetime to benchmark and test it. If anyone is interested in adding these feel free to do it.

So I did some checking and in fact it does not have less allocations, however, the code is cleaner and easier to understand and thus it makes sense to accept it.

Before:

BenchmarkHS512Signing-8   	 1604331	       715.2 ns/op	    1777 B/op	      26 allocs/op

After:

BenchmarkHS512Signing-8   	 1616665	       702.9 ns/op	    1777 B/op	      26 allocs/op

oxisto avatar Feb 21 '23 22:02 oxisto

Thanks @oxisto

moneszarrugh avatar Feb 22 '23 16:02 moneszarrugh