Skip to content
walterorando.com /
Search

Stop the Hidden Performance Tax: Mastering Manual Event Bindings in AL

I once inherited a project where clicking “Post” on a Sales Order took 5 seconds to respond. The culprit? A global event subscriber on the Sales Line table calculating royalties.
The problem wasn’t the logic, it was the scope. That subscriber was firing for every single user, even those who never touched royalty-bearing items. In effect, the entire organization was paying a performance tax for a feature used by only 5% of staff.


⚠️ The Problem: Static Subscriber Bloat
By default, EventSubscriberInstance in AL is Static. That means as soon as your app is published, the subscriber is always listening.
Every time the event fires across every session in the tenant your code executes.
Now imagine 20 different apps all subscribing to the Sales Line table globally. Each post, each update, each trigger… multiplied across every user. The result? Cumulative lag, wasted cycles, and a hidden performance tax that drags down the entire system.


🛠️ The Fix: Manual Event Bindings
Instead of letting subscribers run globally for every session, switch your Codeunit’s EventSubscriberInstance to Manual.
With manual bindings, the subscriber stays dormant until you explicitly activate it for a specific process. That means your heavy logic only runs when it’s truly needed no more hidden performance tax across the tenant.


➡️ Technical Grounding:
– SaaS Available? Yes.
– Runtime/Upgrade? Runtime.
– Bypasses Triggers? No, it manages the subscription to the trigger.


💡 Why It Matters
✅ Zero Global Overhead
Manual bindings mean users who aren’t running your specific process pay no performance penalty. Heavy logic only runs where it’s truly needed.
✅ Smarter State Management.
Because the Codeunit is instantiated as a variable, you can maintain global variables inside the subscriber that persist only for the duration of that process, clean, scoped, and efficient.
✅ Test Isolation
Manual bindings are the professional way to write mock subscribers in Test Codeunits. You can isolate behavior without polluting the rest of the test suite.


‼️ The Trap:
If you forget to call UnbindSubscription, the subscriber stays active for the duration of that user’s session. Always wrap your logic in a try…finally (or ensure the variable goes out of scope) to avoid “zombie” subscribers.


🏷️ The Bottom Line
Don’t make every user pay a performance tax for features they don’t use. If your logic doesn’t need to run 100% of the time, bind it manually.
Manual Event Bindings = precision performance. Your code runs only when it matters, keeping the rest of the system fast and clean.

Leave a Reply

Your email address will not be published. Required fields are marked *