News for hackers. Stuff that matters.
Re:Never create Ruby strings longer than 23 characters by gaius on Wednesday December 11, 2013 @10:47AM (#6888167)
I suppose the thing to do is analyse your app for the average string length, and just recompile your Ruby with that. Would be even better of it was a command line parameter.
Re:Never create Ruby strings longer than 23 characters by throwaway0094 on Wednesday December 11, 2013 @10:49AM (#6888178)
This isn't quite right. Even if your average string length is 1k+, you shouldn't change the embedded string size to 1k+. I think these objects sit on the C stack internally, which doesn't handle large objects like this well.

Also, I would guess the performance gains (from skipping malloc) would wash out the longer your average string gets -- even if the huge stack use doesn't kill your performance for some other reason (blowing the d-cache?).

Re:Never create Ruby strings longer than 23 characters by ben0x539 on Wednesday December 11, 2013 @11:03AM (#6888273)
I don't think these strings ever sit on the C stack, except maybe if some C code/extension is being really clever. The standard representation for variables is a tagged pointer as far as I know, so I would assume that is all that goes on the stack. This optimization probably just saves another level of indirection.
Re:Never create Ruby strings longer than 23 characters by throwaway0094 on Wednesday December 11, 2013 @01:09PM (#6889360)
Hm, ok. Still, at some level fragmentation is eating gobs of space even if correct for the "average".