You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2020/12/02 08:52:37 UTC
[GitHub] [apisix] tokers opened a new issue #2930: optimization: string concatenation in sls-logger.lua
tokers opened a new issue #2930:
URL: https://github.com/apache/apisix/issues/2930
### Issue description
The string concatenation in sls-logger.lua is inefficient, we should optimize it.

https://github.com/apache/apisix/blob/master/apisix/plugins/sls-logger.lua#L135
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] spacewander commented on issue #2930: optimization: string concatenation in sls-logger.lua
Posted by GitBox <gi...@apache.org>.
spacewander commented on issue #2930:
URL: https://github.com/apache/apisix/issues/2930#issuecomment-738866630
Done.
@gy09535
Next time, please refer this issue with `close #xxx`
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] gy09535 commented on issue #2930: optimization: string concatenation in sls-logger.lua
Posted by GitBox <gi...@apache.org>.
gy09535 commented on issue #2930:
URL: https://github.com/apache/apisix/issues/2930#issuecomment-737713975
Please assign to me, I will fix it.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] gy09535 commented on issue #2930: optimization: string concatenation in sls-logger.lua
Posted by GitBox <gi...@apache.org>.
gy09535 commented on issue #2930:
URL: https://github.com/apache/apisix/issues/2930#issuecomment-737238552
Please give some performance testing to prove use string concatenation is not inefficient.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] tokers commented on issue #2930: optimization: string concatenation in sls-logger.lua
Posted by GitBox <gi...@apache.org>.
tokers commented on issue #2930:
URL: https://github.com/apache/apisix/issues/2930#issuecomment-737628759
> Please give some performance testing to prove use string concatenation is not inefficient, I have do the performance test for sls log ,can not find any inefficient issue.
This is a classical bad practice for string concatenation. Just see the following snippet to benchmark it.
```lua
local function concat_100000x_way1(s)
local t = ""
for i = 1, 50000 do
t = t .. s
end
return t
end
local function concat_100000x_way2(s)
local t = {}
for i = 1, 50000 do
t[i] = s
end
return table.concat(t)
end
local function bench(func, s)
local s = os.time()
func(s)
print("cost time: ", os.time() - s)
end
bench(concat_100000x_way1, string.rep("haha", 50))
bench(concat_100000x_way2, string.rep("haha", 50))
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] gy09535 edited a comment on issue #2930: optimization: string concatenation in sls-logger.lua
Posted by GitBox <gi...@apache.org>.
gy09535 edited a comment on issue #2930:
URL: https://github.com/apache/apisix/issues/2930#issuecomment-737238552
Please give some performance testing to prove use string concatenation is not inefficient, I have do the performance test for sls log ,can not find any inefficient issue.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] spacewander closed issue #2930: optimization: string concatenation in sls-logger.lua
Posted by GitBox <gi...@apache.org>.
spacewander closed issue #2930:
URL: https://github.com/apache/apisix/issues/2930
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] tokers commented on issue #2930: optimization: string concatenation in sls-logger.lua
Posted by GitBox <gi...@apache.org>.
tokers commented on issue #2930:
URL: https://github.com/apache/apisix/issues/2930#issuecomment-737770202
@gy09535 Assigned to you. :)
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] gy09535 commented on issue #2930: optimization: string concatenation in sls-logger.lua
Posted by GitBox <gi...@apache.org>.
gy09535 commented on issue #2930:
URL: https://github.com/apache/apisix/issues/2930#issuecomment-737709901
> > Please give some performance testing to prove use string concatenation is not inefficient, I have do the performance test for sls log ,can not find any inefficient issue.
>
> This is a classical bad practice for string concatenation. Just see the following snippet to benchmark it.
>
> ```lua
> local function concat_100000x_way1(s)
> local t = ""
> for i = 1, 50000 do
> t = t .. s
> end
>
> return t
> end
>
>
> local function concat_100000x_way2(s)
> local t = {}
> for i = 1, 50000 do
> t[i] = s
> end
>
> return table.concat(t)
> end
>
>
> local function bench(func, s)
> local s = os.time()
> func(s)
> print("cost time: ", os.time() - s)
> end
>
>
> bench(concat_100000x_way1, string.rep("haha", 50))
> bench(concat_100000x_way2, string.rep("haha", 50))
> ```
got it
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] membphis commented on issue #2930: optimization: string concatenation in sls-logger.lua
Posted by GitBox <gi...@apache.org>.
membphis commented on issue #2930:
URL: https://github.com/apache/apisix/issues/2930#issuecomment-737274098
steps:
- use lua table to cache items
- call table.concat
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org