One of the largest performance bottlenecks in Element.getAttribute (and I
suspect a bunch of other webidl bindings as well) is copying (often very
small) SpiderMonkey strings into heap allocated DOMStrings. It doesn't seem
practical to always use JS strings as they don't use UTF-8 and it would
require a lot more rooting and generally seems like it would require
rewriting a large amount of code. But, it was pointed out that these (often
very small) strings are always heap allocated.

See #6906 and specifically these comments:

https://github.com/servo/servo/issues/6906#issuecomment-159372789
https://github.com/servo/servo/issues/6906#issuecomment-159379936
https://github.com/servo/servo/issues/6906#issuecomment-159383632

I've created a crate[0] that provides a mostly drop-in replacement of
std::string::String but with inline storage for small strings to avoid heap
allocation. It also provides a StringExt trait to abstract string
operations over both InlinableString and std::string::String. I'm planning
on implementing this trait for DOMString as well, making the codegen emit
bindings code that uses InlinableString for stack allocated strings, and
make the webidl interface methods use `StringExt` instead of `DOMString`
directy. My hope is that this will make a good chunk of that performance
bottleneck go away.

[0] https://github.com/fitzgen/inlinable_string

If I bug you on irc with requests for help, please have patience with me :)

If you see something architecturally wrong with this plan, please let me
know sooner rather than later!

Cheers,

Nick
_______________________________________________
dev-servo mailing list
dev-servo@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-servo

Reply via email to