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

optimize: move string concatenation to the C land #73

Closed
wants to merge 2 commits into from

Conversation

doujiang24
Copy link
Member

This patch make cpu from 90% to 40% in my recently project.
I got the below result when I run lgcstat

(gdb) lgcstat
301463 str        objects: max=2012, avg = 31, min=18, sum=9597298
586 upval      objects: max=24, avg = 24, min=24, sum=14064
320345 thread     objects: max=1120, avg = 664, min=424, sum=212712496
213 proto      objects: max=2579, avg = 356, min=74, sum=75945
160947 func       objects: max=144, avg = 20, min=20, sum=3231576
  91 trace      objects: max=1860, avg = 606, min=160, sum=55208
160032 cdata      objects: max=4112, avg = 16, min=12, sum=2564600
1213829 tab        objects: max=6291488, avg = 159, min=32, sum=194150416
272538 udata      objects: max=17694, avg = 440, min=32, sum=119927236

sizeof strhash 2097152
sizeof g->tmpbuf 2048
sizeof ctype_state 4568
sizeof jit_state 3472

total sz 544441311
g->strnum 301463, g->gc.total 544441311
elapsed: 284.000000 sec

There is not big performance difference when the number of string in Lua land is small.
But do string concatenation to the C land performance much better when the number is large.

-- it is faster to do string concatenation on the Lua land
return concat(req)
-- it is much faster to do string concatenation on the C land
-- in some real world (large number of string in Lua)
Copy link
Member

Choose a reason for hiding this comment

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

"in some real world" -> "in real world"
"large number of string in Lua" -> "large number of strings in the Lua VM"

@agentzh
Copy link
Member

agentzh commented Dec 22, 2015

Please tweak your comment a little bit as suggested. Other than that, it looks good to me :) Thanks for your contribution!

@agentzh
Copy link
Member

agentzh commented Dec 22, 2015

I'm thinking (aloud) that this trick may help other cosocket-based lua-resty-* libraries as well :)

@doujiang24
Copy link
Member Author

@agentzh Thanks, just fixed the comment. Yeah, I do think it's worth to use this trick in other cosocket-based lua-resty-* libraries.

agentzh added a commit that referenced this pull request Dec 23, 2015
…on onto the C land. thanks Dejiang Zhu for the patch in #73.
@agentzh
Copy link
Member

agentzh commented Dec 23, 2015

@doujiang24 Patch applied to master. Thanks a lot!

@agentzh agentzh closed this Dec 23, 2015
@doujiang24 doujiang24 deleted the concat branch December 23, 2015 09:05
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

2 participants