2

I have a list of System.IO.Ports.SerialPort objects in one assembly, and I plan to handle the Data_Receieved event from another assembly.

I wonder if this may affect performance somehow. Will it? (I'm afraid I'm not that clear how assemblies are managed by the CLR.) Thank you.

  • 3
    The JIT compiler performs optimization after the various assemblies get resolved, therefore it is able to perform cross-assembly optimization (such as inlining). – Ben Voigt May 01 '13 at 17:01
  • 2
    On the other hand, using `System.IO.Ports.SerialPort` likely has a large detrimental effect on performance. And if you do insist on using it, it would be far better to use `BeginRead` and handle the completion callback. The `DataReceived` event is very badly designed. – Ben Voigt May 01 '13 at 17:02
  • Agree with the advice on using `BeginRead()`., but I'm not sure what alternative there is to using `Serialport` other than messing around with the native API. – Matthew Watson May 01 '13 at 17:08

2 Answers2

6

There should be no impact on performance once the assemblies are loaded.

The only potential impact would be a (very slight) hit to load times. When the assemblies are loaded by the CLR, there is some work involved in loading each assembly. This is generally small enough that it's not noticable, however.

Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373
2

No. When it comes to performance, which assembly types are located in doesn't really matter. The JIT is going to emit the same native code. The only performance penalty would be when initially loading the assemblies, and it's going to be negligible.

cdhowie
  • 158,093
  • 24
  • 286
  • 300