Performance: RunnablePassthrough and RunnableLambda
MEDIUM IMPACT
This concept affects how quickly and efficiently small tasks or functions run within a LangChain workflow, impacting interaction responsiveness and overall execution speed.
from langchain.schema.runnables import RunnablePassthrough passthrough = RunnablePassthrough() result = passthrough.invoke(data)
class CustomRunnable: def invoke(self, input): return input custom = CustomRunnable() result = custom.invoke(data)
| Pattern | Function Calls | Call Stack Depth | Execution Overhead | Verdict |
|---|---|---|---|---|
| Custom class passthrough | 2+ | Increased | Higher due to extra layers | [X] Bad |
| RunnablePassthrough | 1 | Minimal | Minimal overhead | [OK] Good |
| Wrapped function in class | 3+ | Increased | Higher due to wrapping | [X] Bad |
| RunnableLambda with inline function | 1 | Minimal | Minimal overhead | [OK] Good |