Send data as buffer+id vs variable

I was wondering if anyone could tell me what the preferred (in terms of performance)
data representation in Optix programs is.
Think of BRDF materials in form of a struct.
Should I send all materials in a single buffer and link the indices to the geometry instances,
or would it be better to link the materials directly to each geometry instance?
I would need to access the material data in multiple programs/launches each cycle if that changes anything.

For few variables it’s faster to put them into individual variable declarations because of the additional indirection when reading material parameters from a buffer.

I favor the buffer plus index method. In my global illumination path tracer, which concentrates on the simple creation of complex layered materials, I use a context global input buffer with an array of structures to define all material parameters in the scene.
The individual Material node itself only needs a single integer variable to index into that buffer.
The same index is used to present the GUI-side parameters driving these (which is using a different representation of values, e.g. degrees in the GUI vs. radians in the shader.)

The performance difference was in the 1-2% range, definitely not worth the hassle of individual variable declarations per Material node.

The centralized routine to update any material parameter is just so much more convenient if you have many parameters per material. My current material parameter structure defines 36 different color, scalar, and bindless texture ID parameters and each layered material picks a subset from that as needed.

If you animate many parameters at the same time that should also be beneficial.
With a huge number of materials in the scene, animating individual parameters might be more costly due to the map, write, unmap of the whole buffer, though I have not seen any issue of updating individual parameters in the GUI interactively. (So far tried with a maximum of 4096 different materials in a scene.)

Thank you very much for sharing your experience!
I’ll stick to the buffer+index method in that case.