Skip to content

Performance issue in String#codepoints #6061

@jabamaus

Description

@jabamaus

Hi,

I've written an app that runs with mruby or cruby and I noticed that the frame rate was massively degraded when running with mruby. After investigation I narrowed it down to calls to String#codepoints which where happening multiple times per frame. Of course I can, and probably will improve my code to use a cache or eliminate it entirely but I think the method itself can be hugely optimized, after all the way its currently written works fine in cruby.

The implementation in https://github.com/mruby/mruby/blob/master/mrbgems/mruby-string-ext/mrblib/string.rb is:

self.split('').map{|x| x.ord}
I think this is made worse by the fact that the onig_regexp gem replaces String#split with its own version which probably adds a further performance penalty.

Presumably the GC is getting hammered. I guess doing it in C would be the best?

I'm not desperate for this but I thought I'd flag it.

Cheers!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions