[dev-servo] Planning to experiment with inline storage for DOMString / webidl binding codegen

2015-12-01 Thread Nick Fitzgerald
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


Re: [dev-servo] Planning to experiment with inline storage for DOMString / webidl binding codegen

2015-12-01 Thread Jack Moffitt
> 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.

Alan Jeffrey has been investigating issues around string copying as
well. Have you chatted with him to compare notes?

jack.
___
dev-servo mailing list
dev-servo@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-servo


Re: [dev-servo] Planning to experiment with inline storage for DOMString / webidl binding codegen

2015-12-01 Thread Nick Fitzgerald
​On Tue, Dec 1, 2015 at 5:48 PM, Jack Moffitt  wrote:

> > 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.
>
> Alan Jeffrey has been investigating issues around string copying as
> well. Have you chatted with him to compare notes?
>

​I was not aware of that. I'm interested in Alan's initial findings​ and
approach as well! (Pung for more info here:
https://github.com/servo/servo/issues/6906#issuecomment-161153975)
___
dev-servo mailing list
dev-servo@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-servo


Re: [dev-servo] Planning to experiment with inline storage for DOMString / webidl binding codegen

2015-12-01 Thread Alan Jeffrey
Yes, I've done some experiments with this. Inlining small strings didn't
help as much as I'd hoped, I suspect because they're being converted to
Strings or JSStrings a lot. I'm still in the middle of experimenting, I'm
hoping to write up soon. The code is at
https://github.com/asajeffrey/servo/tree/string_representation_experiments
although it's a bit of a mess.

A.



On Tue, Dec 1, 2015 at 7:48 PM, Jack Moffitt  wrote:

> > 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.
>
> Alan Jeffrey has been investigating issues around string copying as
> well. Have you chatted with him to compare notes?
>
> jack.
> ___
> dev-servo mailing list
> dev-servo@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-servo
>
___
dev-servo mailing list
dev-servo@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-servo


Re: [dev-servo] Planning to experiment with inline storage for DOMString / webidl binding codegen

2015-12-01 Thread Simon Sapin

On 02/12/15 02:39, Nick Fitzgerald wrote:

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.

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


There’s also [1], already in used in Servo in some places, which behaves 
like Vec but stores items inline up to a certain length. I’ve also 
been playing with [2] to be like String but with a generic backing 
storage. (I’ve used it in [3] to return a single code point in UTF-8 as 
StringWrapper<[u8; 4]>.)


Would it make sense to converge with some of these?

[1] https://github.com/servo/rust-smallvec
[2] 
https://github.com/SimonSapin/rust-std-candidates/blob/master/string-wrapper/lib.rs

[3] https://github.com/SimonSapin/rust-utf8


--
Simon Sapin
___
dev-servo mailing list
dev-servo@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-servo