Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upUse a phf map for the WebGL extension registry #20357
Comments
|
I would like to take on this issue, if possible. What files or parts of the project handle the WebGL extension registry? |
|
I think I found what parts of the application handle the HashMap of extensions: |
|
servo/components/script/dom/webgl_extensions/extensions.rs Lines 267 to 276 in 1994712 |
|
@jdm Thanks, I didn't see that. Do you think that the |
|
Yes, that's what we use in other places in the codebase too. |
|
Alright, I've been busy the past few days, but I had some time to work on this today. Question: should I define the PHF map inside the |
|
I'm almost finished, I'll make a PR either today or tomorrow. I tried to find an idiomatic way to create a list of types so I could could just generate the map in One problem I did encounter was the fact that Should I make tests for the changes I have made? |
|
The changes should be covered by the existing webgl tests. |
|
I'm sorry for the wait.. I've been on vacation recently, and I haven't had the time to work on this. I forgot to mention one other problem I encountered: I need to import the extension types during the |
|
The macro approach did work, but I still need to implement the traits that cannot be automatically derived due to the missing implementation on the PHF map type. My plan is to create trait implementations for the PHF map inside the crates of the trait implementations, which are within the servo repository, but outside of the |
|
Are you referring to the WebGLExtension trait, or some other type(s)? In general, I agree that moving types that you require at build time into a separate crate that |
|
It would definitely be easier to answer your questions if you pushed your code to a branch so it could be examined, and mentioned the error messages that appear. |
|
You're right, I'll push the changes to my fork of the repo. I already fixed the problems with code generation (I just used inline macro generation instead), so I'm not worried about importing types at build time. My question (rephrased) was if I should implement the |
|
Those would be useful implementations, yes! |
|
Alright, I'll push to my fork once I finish implementing those. |
|
I'm sorry, I haven't had much time to work on this recently. I did work on this a few days ago, and I found a few things: first of all, you have to use |
|
Alright, so I did some more work today, and unfortunately I can say that moving this hash map over to a PHF map requires a lot of non-trivial, and some downright impossible things. First of all, I decided to make the map static, so it didn't need to be contained inside the |
|
Yeah, that sounds much more complex than I anticipated; sorry! A lazy_static sounds like a reasonable compromise. |
|
Alright, I've pushed the code: https://github.com/jacksoncoder/servo. I also added the |
|
Should I make a PR? |
|
Looking at the code, I see a problem with the current implementation. The WebGLExtensionWrapper type requires JSTraceable so that when the GC encounters a WebGLExtensions object it knows what to do with the We could fix this by adding a GC hook that specifically traces the hashtable in servo/components/script/script_runtime.rs Line 444 in e7791f9 |
|
So essentially, the problem is that having a static hash map results in the possibility of dangling pointers, where data the extensions are keeping track of are being garbage collected because the GC doesn't know the hash table exists? And in order to fix it, we'll have to make the hash table thread-local and call |
|
All I wanted to replace is the correspondance from |
|
At this point, I think that creating a thread-local lazy_static HashMap would be nearly the same thing as just having the HashMap be part of the |
There is no need to build a HashMap at runtime etc, we could just generate it at compile-time.