473,399 Members | 4,177 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Using CSharpCodeProvider to create MANY assemblies

I am planning to use the CSharpCodeProvider to generate some compiled
functions in my app.

In my current implementation, All of these functions are generated in
one swipe... thus they all invoke the compiler once, and create only
one DLL. My new requirement tells me that I need to be more
dynamic... that I can't queue up all of these functions... I actually
need to do them more on demand.

The number of times this happens can be as many as 10,000 times...
each with a different calculation. This would mean that I invoke the
compiler 10,000 times and create 10,000 in-memory DLLs. This idea
scares me... can .NET handle that many DLLs being linked to the app?

Does anyone know about the performance overhead of such an endeavor?
I am about to write some tests to gather data, but I was wondering if
anyone out there has experience with this type of execution. Am I
going to run into performance penalties for invoking the compiler that
many times? Am I going to run into performance penalties for having
that many DLLs in the app domain? If so, are there any workarounds
that anyone knows of?

Thanks,
Brian
Nov 26 '07 #1
7 2526
Brian,

I would say you are probably going to start seeing some issues when you
try and load 10,000 assemblies into an app-domain. The assemblies
themselves are small, but the CLR is still going to have overhead in the
form of assembly, module, and type info for each assembly.

As for your requirement, does it state that you have to have separate
assemblies, or that you have to be able to call them dynamically (and not
queue it all up).

If the case is the former, then I would say revisit the requirements.
What's the justification for generating all those assemblies?

If the case is the former, I would look into creating an in-memory
assembly, with a single module, and add new global methods/types as needed
and implementing them using IL, instead of the codedom provider and
compiling separately.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Bilz" <Br**********@gmail.comwrote in message
news:9c**********************************@y5g2000h sf.googlegroups.com...
>I am planning to use the CSharpCodeProvider to generate some compiled
functions in my app.

In my current implementation, All of these functions are generated in
one swipe... thus they all invoke the compiler once, and create only
one DLL. My new requirement tells me that I need to be more
dynamic... that I can't queue up all of these functions... I actually
need to do them more on demand.

The number of times this happens can be as many as 10,000 times...
each with a different calculation. This would mean that I invoke the
compiler 10,000 times and create 10,000 in-memory DLLs. This idea
scares me... can .NET handle that many DLLs being linked to the app?

Does anyone know about the performance overhead of such an endeavor?
I am about to write some tests to gather data, but I was wondering if
anyone out there has experience with this type of execution. Am I
going to run into performance penalties for invoking the compiler that
many times? Am I going to run into performance penalties for having
that many DLLs in the app domain? If so, are there any workarounds
that anyone knows of?

Thanks,
Brian

Nov 26 '07 #2
Sorry, the second "former" should be "latter".
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote in
message news:%2****************@TK2MSFTNGP03.phx.gbl...
Brian,

I would say you are probably going to start seeing some issues when you
try and load 10,000 assemblies into an app-domain. The assemblies
themselves are small, but the CLR is still going to have overhead in the
form of assembly, module, and type info for each assembly.

As for your requirement, does it state that you have to have separate
assemblies, or that you have to be able to call them dynamically (and not
queue it all up).

If the case is the former, then I would say revisit the requirements.
What's the justification for generating all those assemblies?

If the case is the former, I would look into creating an in-memory
assembly, with a single module, and add new global methods/types as needed
and implementing them using IL, instead of the codedom provider and
compiling separately.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Bilz" <Br**********@gmail.comwrote in message
news:9c**********************************@y5g2000h sf.googlegroups.com...
>>I am planning to use the CSharpCodeProvider to generate some compiled
functions in my app.

In my current implementation, All of these functions are generated in
one swipe... thus they all invoke the compiler once, and create only
one DLL. My new requirement tells me that I need to be more
dynamic... that I can't queue up all of these functions... I actually
need to do them more on demand.

The number of times this happens can be as many as 10,000 times...
each with a different calculation. This would mean that I invoke the
compiler 10,000 times and create 10,000 in-memory DLLs. This idea
scares me... can .NET handle that many DLLs being linked to the app?

Does anyone know about the performance overhead of such an endeavor?
I am about to write some tests to gather data, but I was wondering if
anyone out there has experience with this type of execution. Am I
going to run into performance penalties for invoking the compiler that
many times? Am I going to run into performance penalties for having
that many DLLs in the app domain? If so, are there any workarounds
that anyone knows of?

Thanks,
Brian


Nov 26 '07 #3
On Nov 26, 2:03 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
Brian,

I would say you are probably going to start seeing some issues when you
try and load 10,000 assemblies into an app-domain. The assemblies
themselves are small, but the CLR is still going to have overhead in the
form of assembly, module, and type info for each assembly.
No, there is no requirement to create multiple DLLs... just that the
functions be dynamically generated. The functions look to the user
like math equations... wrap their math equations with C# methods,
compile them, and run them against their inputs.

I will look into the idea of inserting methods via IL. I have never
done anything like that. If I can't use C# code, it might defeat the
purpose, since I am using this method to avoid parsing their
functions. They write something like ((input1 * input2)/input3) and I
write that out directly as a C# method with 3 parameters.

Thanks,
B
Nov 26 '07 #4
Brian,

Well, you would have to parse it anyways to get the parameter names.
Beyond that, you would have to map the operators and whatnot to IL (which
might be no small task).

You might be able to get away with compiling to memory and then taking
the IL from the compiled unit and then placing it dynamically in your type.

I would test creating separate assemblies, and see if you see any
noticable change in your app for the load you would expect to normally
handle. If it works, then I would leave it at that. Only if it doesn't
would I venture down this path.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Bilz" <Br**********@gmail.comwrote in message
news:f9**********************************@e25g2000 prg.googlegroups.com...
On Nov 26, 2:03 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
>Brian,

I would say you are probably going to start seeing some issues when
you
try and load 10,000 assemblies into an app-domain. The assemblies
themselves are small, but the CLR is still going to have overhead in the
form of assembly, module, and type info for each assembly.

No, there is no requirement to create multiple DLLs... just that the
functions be dynamically generated. The functions look to the user
like math equations... wrap their math equations with C# methods,
compile them, and run them against their inputs.

I will look into the idea of inserting methods via IL. I have never
done anything like that. If I can't use C# code, it might defeat the
purpose, since I am using this method to avoid parsing their
functions. They write something like ((input1 * input2)/input3) and I
write that out directly as a C# method with 3 parameters.

Thanks,
B

Nov 26 '07 #5
On Nov 26, 4:05 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
I would test creating separate assemblies, and see if you see any
noticable change in your app for the load you would expect to normally
handle. If it works, then I would leave it at that. Only if it doesn't
would I venture down this path.
Yes, I agree with that... I am really just investigating right now. I
just don't want to go down a design path that falls apart as it
scales.

I looked into the DynamicMethod class... I thought about what you
said... compile it into a new assembly and transfer the IL over to the
primary assembly. Is there a way to unload the temp assembly? I
don't know that I have ever UNloaded an assembly dynamically.

Thanks for ALL the help,
B
Nov 26 '07 #6
Bilz,

If you compile the assembly, I don't know that it gets loaded by the
CLR. There might be a managed representation of it in memory, but I don't
know that it's considered loaded.

If it is loaded into memory though, you are going to have to do it in a
separate app domain, so that you can unload it.

Is the parsing that difficult to do? I ask, because if it is not, then
I would recommend building some sort of parser/graph tree for your
expressions and then creating the IL from that.

If you are using .NET 3.5/C# 3.0, you could even use Expressions to help
build your methods for you, as it should make it much, much easier.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Bilz" <Br**********@gmail.comwrote in message
news:a6**********************************@d4g2000p rg.googlegroups.com...
On Nov 26, 4:05 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
> I would test creating separate assemblies, and see if you see any
noticable change in your app for the load you would expect to normally
handle. If it works, then I would leave it at that. Only if it doesn't
would I venture down this path.

Yes, I agree with that... I am really just investigating right now. I
just don't want to go down a design path that falls apart as it
scales.

I looked into the DynamicMethod class... I thought about what you
said... compile it into a new assembly and transfer the IL over to the
primary assembly. Is there a way to unload the temp assembly? I
don't know that I have ever UNloaded an assembly dynamically.

Thanks for ALL the help,
B

Nov 27 '07 #7
Bilz <Br**********@gmail.comwrites:
I looked into the DynamicMethod class... I thought about what you
said... compile it into a new assembly and transfer the IL over to the
primary assembly. Is there a way to unload the temp assembly? I
don't know that I have ever UNloaded an assembly dynamically.
Assemblies are only unloaded, if the (last) AppDomain using it is
unloaded. So temporary assemblies should be loaded only in an own
AppDomain to allow later unloading.

Best regards,
Martin
Nov 27 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Sherif ElMetainy | last post by:
Hello I am making an application that generates source code. I am facing some problems. 1- How can I generate code that uses the c# 'params' keyword to specify multiple arguments? I tried 2...
2
by: Diego_Atos | last post by:
I want to create objects using directX. I downloaded SDK version of DirectX. I've installed it. Which is the right dll to add to references? I can't find it. thanks -- -Diego (Atos)-
7
by: Clint Herron | last post by:
Howdy! I posted this question on CSharpCorner.com, but then realized I should probably post it on a more active newsgroup. This will be my only cross-post. I'm creating a game engine, and...
3
by: Amjad | last post by:
Hi, I just wrote a test Windows Service that creates a text file on startup (please see my code below). The file is never created. Protected Overrides Sub OnStart(ByVal args() As String) Dim...
2
by: sklett | last post by:
I added a 3rd party control to my asp.net app on my development machine. However, when I published the site to the main server, I'm getting a Configuration error that states in can't find the...
6
by: moondaddy | last post by:
will CodeDom create XAML windows or just regular windows forms? If so, how to I tell it to create a xaml window instead of a windows form? thanks -- moondaddy@noemail.noemail
0
by: Nik Loutchanski | last post by:
Hi, I'm using dynamic code generation in an ASP.NET 2.0 web service to create proxy classes for other web services with the intention to cache the dynamically compiled proxy types (methodInfo...
3
by: Marco Shaw | last post by:
I've got some C# code to create a custom PowerShell cmdlet with these statements: .... using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; .... ...
2
by: Alexander Vasilevsky | last post by:
How to configure CSharpCodeProvider that can be used Linq- improve language? http://www.alvas.net - Audio tools for C# and VB.Net developers
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.