-
Notifications
You must be signed in to change notification settings - Fork 148
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
String Type #46
Comments
|
Thanks! Fixed.
Similarly to the check for a bogus global, if |
@espadrine: How do you statically check that |
@michaelficarra How do you statically check that Those are part of the runtime checks at linking time. |
So you'd like to add it to this list? |
No. It isn't meant to be a function call in the standard library. |
The problem is that the prototype can change after linking. We avoid that with standard library stuff by saving them in the asm closure. But if we call This isn't the only challenge here - adding this means support in the None of which is impossible, but the question is the motivation. if it's just efficient string processing, we should measure that first. Regarding string efficiency, there is an idea to do a StringView for typed arrays. Basically a typed array is a view into an ArrayBuffer, and a StringView would view the same buffer but present it as string data (C-style null-terminated). If string performance is a concern, this might be worth investigating too. |
Hmm, I see. Can we add it to the standard library, then, like @michaelficarra suggested? The call can look like
I would view such a construct as immutable. The length of the string doesn't change, its content doesn't either. I am not sure how I feel about StringView for two reasons:
That said, supporting a wilder collection of string operations than simply reading a character at a given index, built-in, can be nice. I'm just really not sure we can be faster than normal JS there. |
Actually, let's think about this for a bit, is it possible, that we could optimize specific instances of UInt16Array conversion and back to work efficientlly, and without conversion? I mean |
I believe introducing string support would be beneficial at least for lljs. As it stands, even a basic "hello, world" fails to validate using James Long's lljs fork, furthermore if you were to do any webgl using lljs that would also fail to validate due to the shaders requiring strings. If there were support for fixed-length strings, and possibly support in stdlib for string generics (which could be done as a shim in other browsers like Math.imul) that would cover a lot of basic use cases |
Tim, while string support would be nice, you don't need it to use WebGL. You can load your shaders in js land and only do the computationally expensive stuff in asm.js. My cloth demo uses WebGL (http://jlongster.com/s/lljs-cloth/), you can see the whole program here: https://github.com/jlongster/lljs-cloth/blob/master/verlet.ljs |
You're completely right. I would like to be able to do a whole app in LLJS, but that would require lljs/asm supporting strings, or possibly being able to mark whether a lljs function/struct should use asm or not (which would likely introduce a whole host of other complications). For the time being your solution works very well though |
Note that strings are not usually implemented as a flat array of u16 under the hood. In order to support efficient string append, a linked data structure (such as "ropes") is usually used. So it's not necessarily straightforward to provide a view of the UTF16 data backing a string. |
Awesome, that looks really good |
Thank you ;) |
you can help me to find bugs ;) |
haha yeah I'd be more than happy to do so, does that mean that it's in nightly now? |
of course! I completed it on June, 6... ;) EDIT: I fixed a bug just now! |
Fantastic! I'll give it a crack after work |
Sorry, when you say it's in nightly, do you mean I need to copy stringview.js from the page you linked and then use it, or do you mean I can just call a StringView from my code. The reason I ask is because I've updated nightly and Im getting a reference error |
You need to copy stringview.js from the page I linked...! P.S. Look at the revision... when I change something I update the revision number...:
Bye :) |
Fantastic. Been playing with it for a little, looks like it has potential. Will have to wait until it works with asm to know for sure (or if it does, an example would be great because I can't get it to validate) |
Great :)
Good hacks ;) P.S. I also don't like very much the name of the property "stringView.bufferView". Have you any name suggestion alternative to "bufferView"? :) |
Quick review: |
@cscott
I made StringView as a generic API... asm.js is only one of its possible usage, I think...
Yes, sorry for my poor english, I'm italian ;) when I use the word "character" i mean "codepoint".
The return of toBase64() corresponds to the bytes of the stringView encoded into a base64 string, even when the stringView is UTF-16/UTF-32 encoded.
Yes ;) I'll try to improve the english of that page...
It is an idea. But it it would be only an "aesthetical" idea I think, because the only thing which would change would be some "if" statements...: instead of 'if (stringView.encoding === "UTF-8")' there will be something like 'if (stringView.constructor === UTF8StringView)'... etc... during conversions. And in some cases it is not important the encoding choosen, so I don't know if it would be a good idea to split the StringView constructor... |
That's why I'm surprised that this discussion is taking place in the asm.js bugtracker.
You need to specify endianness, then; the underlying ArrayBufferView leaves this undefined.
Virtual method dispatch is your friend. |
I haven't published that library elsewhere, so I haven't a bugtracker. I think that a good idea would be to move this discussion to my MDN discussion page...: https://developer.mozilla.org/en-US/docs/User_talk:fusionchess
Only one endian is supported: the one choosen by the JavaScript engine!
My syntax cames from tradition... like in Java...: new OutputStreamWriter(System.out, "UTF-16"); |
@cscott |
Out of curiosity, what are you guys planning to make (or have made) with asm.js + StringView? |
Could we consider the inclusion of string types?
It may be an immutable subtype of
extern
.String type marker:
It would have the following expressions:
str.length
: size of the string (a constant). Type:unsigned
.str.charCodeAt(index)
: character code, a nonnegative integer less than 2^16. Type:(unsigned) → fixnum
.This is motivated by the idea that converting an external string into a typed array before passing it in an asm.js exported function is probably not the most efficient approach. Yet, in my experience, string parsing in JS can be boosted a lot.
The text was updated successfully, but these errors were encountered: