coreylowman / cudarc

Safe rust wrapper around CUDA toolkit

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Change the modules map to use &'static str instead of String.

RylanYancey opened this issue · comments

The CudaDevice stores the modules in an RwLock<BTreeMap<String, CudaModule>>. This makes me concerned, since I will have ~100 modules loaded for my application and comparing heap strings this way is a very slow process. I suggest using &'static str and a HashMap. This will allow us to avoid uneccessary heap allocations and decrease the number of comparisons needed when searching for a module.

pub struct CudaDevice {
     modules: RwLock<HashMap<&'static str, CudaModule>>,
     ... etc
}

Benchmarking is obviously required to be certain. I look forward to hearing your thoughts, I'm a college student and would love to understand your process.

It is also entirely possible the compiler is doing all of this for us.

You can't use dynamically constructed names for your modules with &'static str. For you case, in general 100 strings isn't going to add much overhead, so I wouldn't worry about that!