-
Notifications
You must be signed in to change notification settings - Fork 548
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
Proper string type for rolldown #427
Comments
I would give a try on https://github.com/dudykr/ddbase/tree/main/crates/hstr. It would be wonderful if @overlookmotel could give some suggestions. |
The downside: With the new string type rolldown used(let's call it Rstr for now), there are three kinds of string type now.
For oxc itself, situations like scope analysis or transform, they all required to pull out string value from oxc ast, so So far, we could see that only With |
I can provide a unsafe We already have the unsafe |
😅 I don't see it this way. |
@hyf0 Good to meet you! I'm not at all familiar with Rolldown codebase yet, so I may be missing the point, but here are some thoughts: The intent was for
The implications are:
Would that fulfill most of the requirements for The parts I'm not sure about are:
For inline strings, maybe neither of these is required:
For non-inline strings, perhaps one or other of these could use the spare 4 bytes in I'm don't know how common hashing strings is in Rolldown, so how important it is for performance to pre-calculate hashes. Like I said, I'm not at all familiar with Rolldown yet, so sorry if I'm totally missing the point. If I am, please correct me! |
The other solution, I guess, is to ensure OXC's allocator and ASTs stay alive while Rolldown is processing those files. Then maybe |
Good to know all this, but the current implementation seems not that delicate.
This seems promising. Why not take a further step and make My point so far is that |
I totally see your point about local optimums. I guess what you're asking for here is a general-purpose owned string type. However, as far as I understand, it's unfortunately not possible in OXC's AST, without fundamental changes to OXC. To retrace how we got here: Original problem was a memory leak (oxc#1803). Cause of the leak was that oxc#2294 fixed the leak but used an unsound transmute to do so. oxc#2497 removed the unsoundness, by introducing a lifetime - making it explicit that There's only 3 ways around this that I can see:
Personally, I don't think (1) is a good option. It would significantly impact OXC's performance, and the arena also enables some significant features which are otherwise impossible (oxc#2409). The choice between (2) and (3) is a trade-off between performance and ergonomics. Again, this is just my personal view, but I tend to think that OXC semantic and transfomer could move to (3) without too much trouble. Lifetimes are a pain, but in this case personally I don't find them so bad because all the lifetimes are the same - everything lives as long as the allocator. For Rolldown, I don't know enough to have any opinion on which is the best trade-off. But from my understanding, I don't think it's possible to square the circle of combining an owned string type with the arena allocator. The design outlined above is intended to minimize the cost of conversion to an owned type where that's needed, but it can't be removed entirely. Incidentally, the same dilemma also exists for the other non-owning types in OXC's AST - Does this make any sense? |
I don't quite get this one. oxc could use an owned string type with keeping arena. For example, we could simply replace the I also agree that to enable oxc-project/oxc#2409, everything in the oxc ast should be allocated in the arena. I just consider this is a trade-off issue. If this feature is important enough, I totally agree that it's understandable that to have a unique string type just optimized for the case. |
The whole AST has no The allocator |
Oh, now I understand the I could think of the downsides, recursive dropping hurts the advantage using arena. Tough. |
Updates: I'm going to using a new string type to replace This no doubtfully causes some extra converting, slows down the general bundling performance. But we can live with it so far. Let's see if we could find some Zero-Cost Abstractions solutions in the futures. For example make the string type a generic type or some other customized ways. It's pleasure to discuss with @overlookmotel, who always make things easy to understand to everyone. |
Can you type alias |
Yeah. I'm gonna to using new type instead of type alias and wrap |
Thanks @hyf0. Some people think I just talk too much! Glad you appreciate my long winding writing. Is it infeasible to work with I guess the other big outstanding question is hashing. Would we be better off (both in OXC and Rolldown) if This has pluses and minuses:
Whether it'd be a gain probably depends on frequency of comparisons vs creations, and whether the Boshen knows this area better than me. servo/string-cache#268 |
Let's reopen this if we find string type is the bottleneck in the profile. |
Rolldown used oxc
Atom
as the default string type.After oxc-project/oxc#2295 and oxc-project/backlog#46, oxc
Atom
can't be used as a general purposed string type anymore. Not to mentioned that it lacks characteristics that bundler required.To make updating oxc easier, we need to replace the current oxc
Atom
and use a new string type as the default. And to gain potential performance, the new string type should beContexts:
Atom
is not a general purposed string type anymore, we need to converting theAtom
to a new string type. This costs some tax just for converting.The text was updated successfully, but these errors were encountered: