Repository: brendanzab/gl-rs (language: rust)

Issue:
Slow build time for gl::load_with usages
On my i5-3550 this code takes 3.2 seconds to build, which is quite a bit taking into account it is only loading the OpenGL library.

```
extern crate glutin;
extern crate gl;

fn main() {
    let window = glutin::Window::new().unwrap();
    unsafe { window.make_current() };
    gl::load_with(|symbol| window.get_proc_address(symbol));
}
```

It was tested with rustc 1.0.0-nightly (dfc5c0f1e 2015-02-18).



Discussion / hints:
#406 should have made this somewhat faster, but the main problem seems to be that `load_with` is generic and is thus inlined into the using crate instead of being simply linked against (like `#[inline]` functions). Can probably be fixed by making `load_with` take a `&FnMut`.

Also getting really slow builds here (much slower than 3 seconds on a Celeron laptop).

@jonas-schievink Are you saying that it can be fixed by the user of the `gl` crate, or something needs to change in the crate? Can you give an example?
@winduptoy A lot of stuff has changed since I made that comment, so this needs to be reevaluated. But most likely you'll end up tuning the code generated by `gl-rs` to compile more efficiently.
@jonas-schievink thanks. Any tips on how I might go about doing that? I'm afraid I don't understand the alternative methods available in this Rust setup. Is there a way I can setup a module to take advantage of the incremental compilation?

For comparison, a simple `glutin` + `gl` window is compiling in 1 minute and 8 seconds on my Celeron laptop. Commenting out the `gl::load_with` line brings the compilation time down to 6 seconds (obviously panics at runtime). 6 seconds is bearable, but 1 minute is not for simple changes.
I'm not sure how the code generated by gl-rs looks today, but 1 minute does sound like rustc is at least partially at fault. I don't have anything more specific, sorry.
Yep, we'll probably have to look at things again
I'm pretty sure we removed the templates... I might not have remembered to close this issue
This is still the case for 0.11, `gl::load_with` increases build time from 2 to 15 seconds compared to loading pointers individually.
This is still a problem for me. Even with incremental compilation, using `load_with` adds several seconds to the build time. 

I'm not sure what the problem is now, but it looks like `gl::load_with` still calls roughly 700 other `load_with` functions from submodules. The submodule's `load_with` still have the closure as generic type and not as `&mut dyn FnMut`. They are also not marked with `#[inline(never)]`. I'd bet that changing these two things would improve things a lot. What do you think? 
Ah yes, that seems like the culprit!
Now that I think about it, I would probably *also* create an inner function inside `gl::load_with` which takes `&mut dyn FnMut` and is also marked with `#[inline(never)]`. The outer `gl::load_with` would then only call the inner one. That way, the 700 calls are not inlined into user code. 

I could submit this as PR, if you want. Or do you want to do it?
I'd definitely accept a PR! I'm not doing much graphics work at the moment, so I'm kind of relying on contributions at this stage.
@brendanzab Do you think the improvements from #495 are good enough to justify closing this issue? At least for now? And/or do you want to wait until the patch is released to crates.io? Are you planning to release this in a point release or with "0.13.0"?
Thanks for the reminder! I'm also getting asked here: #494. I'm guessing this is a breaking change (even with the pinned travis version), so I'll ratchet up a new minor version.

Fix patch:
diff --git a/gl/Cargo.toml b/gl/Cargo.toml
index 861509d9..4532320c 100644
--- a/gl/Cargo.toml
+++ b/gl/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "gl"
-version = "0.12.0"
+version = "0.13.0"
 authors = [
     "Brendan Zabarauskas <bjzaba@yahoo.com.au>",
     "Corey Richardson",
@@ -17,7 +17,7 @@ categories = ["api-bindings", "rendering::graphics-api"]
 keywords = ["gl", "egl", "opengl", "khronos"]
 
 [build-dependencies]
-gl_generator = { version = "0.11.0", path = "../gl_generator" }
+gl_generator = { version = "0.13.0", path = "../gl_generator" }
 
 [dev-dependencies]
 glutin = "0.19.0"
diff --git a/gl_generator/Cargo.toml b/gl_generator/Cargo.toml
index d2a268f3..f3af1ea5 100644
--- a/gl_generator/Cargo.toml
+++ b/gl_generator/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "gl_generator"
-version = "0.11.0"
+version = "0.13.0"
 authors = [
     "Brendan Zabarauskas <bjzaba@yahoo.com.au>",
     "Corey Richardson",
diff --git a/webgl_generator/utils.rs b/webgl_generator/utils.rs
index 1670510a..b2b4fcff 100644
--- a/webgl_generator/utils.rs
+++ b/webgl_generator/utils.rs
@@ -26,7 +26,6 @@ pub fn multimap_append<K: Ord + Clone, V: PartialEq>(
 /// Best-effort attempt to render HTML into a doc-comment which can
 /// be placed in the generated code.
 pub fn convert_html_to_doc_comment(html: &str) -> String {
-    use html2runes;
     use regex::RegexBuilder;
 
     // Create doc comments
diff --git a/webgl_generator/webgl_registry/mod.rs b/webgl_generator/webgl_registry/mod.rs
index 01f0a1b0..ab47c537 100644
--- a/webgl_generator/webgl_registry/mod.rs
+++ b/webgl_generator/webgl_registry/mod.rs
@@ -59,7 +59,6 @@ impl<'a> Exts<'a> {
 
     fn enumerate(&self) -> Vec<ExtensionIDL> {
         use regex::{Regex, RegexBuilder};
-        use xml;
 
         // The Khronos IDL files are... not quite right, so let's fix them up!
         let enum_regex = Regex::new("([(, ])enum\\b").unwrap();


Test patch: