1 Notes on memory allocation
2 --------------------------
4 A run of the AllocationProfile shows that the compiler allocates roughly
5 30 megabytes of strings. From those, 20 megabytes come from
8 See the notes on current_container problems below on memory usage.
13 Obtaining the list of namespaces is an expensive process because
14 Reflection.Emit does not provide a quick way of pulling the data out,
15 and it is too slow to load it.
17 Calling GetNamespaces on my machine (1Ghz):
19 * Takes half a second with the standard assemblies (corlib + System);
20 Fetching the types from it takes 0.0028650 seconds.
22 * Loading the top 10 largest assemblies we ship with Mono makes MCS take
23 8 seconds to startup the first time, subsequent invocations take 2 seconds.
25 Fetching all the types (Assembly.GetTypes ()) for all the assemblies takes
28 So pulling all the types takes very little time, maybe we should look into our
29 Hashtable implementation to make it more optimal.
31 This prohibits re-writting SimpleName to take advantage of
32 knowing the namespace names in advance. Knowing the namespaces in advance
33 would allow me to reduce the guesswork in which we are currently engaged
34 to find a type definition.
39 With something like `System.Object', LookupTypeReflection will be called
40 twice: once to find out that `System' is not a type and once
43 This is required because System.Reflection requires that the type/nested types are
44 not separated by a dot but by a plus sign.
46 A nested class would be My+Class (My being the toplevel, Class the nested one).
48 It is interesting to look at the most called lookups when bootstrapping MCS:
51 713 LTR: System.Globalization
52 822 LTR: System.Object+Expression
53 904 LTR: Mono.CSharp.ArrayList
54 976 LTR: System.Runtime.CompilerServices
56 1118 LTR: System.Runtime
57 1208 LTR: Mono.CSharp.Type
58 1373 LTR: Mono.Languages
59 1599 LTR: System.Diagnostics
61 2302 LTR: System.Reflection.Emit
62 2515 LTR: System.Collections
63 4527 LTR: System.Reflection
64 22273 LTR: Mono.CSharp
69 The top 9 lookups are done for things which are not types.
71 Mono.CSharp.Type happens to be a common lookup: the class Type
72 used heavily in the compiler in the default namespace.
76 Then `Type' is looked up alone a lot of the time, this happens
77 in parameter declarations and am not entirely sure that this is
78 correct (FindType will pass to LookupInterfaceOrClass a the current_type.FullName,
79 which for some reason is null!). This seems to be a problem with a lost
80 piece of context during FindType.
82 System.Object is also used a lot as a toplevel class, and we assume it will
83 have children, we should just shortcut this.
87 Adding a cache and adding a catch for `System.Object' to flag that it wont be the
88 root of a hierarchy reduced the MCS bootstrap time from 10.22 seconds to 8.90 seconds.
90 This cache is currently enabled with SIMPLE_SPEEDUP in typemanager.cs. Memory consumption
91 went down from 74 megs to 65 megs with this change.
96 Instead of the hack that *knows* about System.Object not having any children classes,
97 we should just make it simple for a probe to know that there is no need for it.
100 ---------------------
102 We could probably use a different system to represent names, like this:
109 So `System.ComponentModel' becomes:
112 y: (ComponentModel, x)
114 The problem is that we would still need to construct the name to pass to
117 current_container/current_namespace and the DeclSpace
118 -----------------------------------------------------
120 We are storing fully qualified names in the DeclSpace instead of the node,
121 this is because `current_namespace' (Namepsace) is not a DeclSpace like
124 The reason for storing the full names today is this:
136 The problem is that we only use the namespace stack to track the "prefix"
137 for typecontainers, but they are not typecontainers themselves, so we have
138 to use fully qualified names, because both A.X and A.Y would be entered
139 in the toplevel type container. If we use the short names, there would be
142 To fix this problem, we have to make namespaces DeclSpaces.
144 The full size, contrasted with the size that could be stored is:
146 Size of strings held: 368901
147 Size of strings short: 147863
150 Size of strings held: 212677
151 Size of strings short: 97521
154 Size of strings held: 128055
155 Size of strings short: 35782
158 Size of strings held: 117896
159 Size of strings short: 36153
162 Size of strings held: 194527
163 Size of strings short: 58064
165 System.Windows.Forms:
166 Size of strings held: 220495
167 Size of strings short: 64923
172 1. Create a "partial" emit context for each TypeContainer..
174 2. EmitContext should be partially constructed. No IL Generator.
176 interface_type review.
178 parameter_array, line 952: `note: must be a single dimension array type'. Validate this
180 Dead Code Elimination bugs:
181 ---------------------------
183 I should also resolve all the children expressions in Switch, Fixed, Using.
188 Pinned and volatile require type modifiers that can not be encoded
189 with Reflection.Emit.
191 Properties and 17.6.3: Finish it.
193 Implement base indexer access.
195 readonly variables and ref/out
200 * Check for Final when overriding, if the parent is Final, then we cant
205 I have not figured out why the Microsoft version puts an
206 `instance' attribute, and I am not generating this `instance' attribute.
208 Explanation: The reason for the `instance' attribute on
209 indexers is that indexers only apply to instances
211 * Break/Continue statements
213 A finally block should reset the InLoop/LoopBegin/LoopEnd, as
214 they are logically outside the scope of the loop.
216 * Break/continue part 2.
218 They should transfer control to the finally block if inside a try/catch
221 * Method Registration and error CS111
223 The way we use the method registration to signal 111 is wrong.
225 Method registration should only be used to register methodbuilders,
226 we need an alternate method of checking for duplicates.
229 > // CSC sets beforefieldinit
231 > // .cctor will be generated by compiler
232 > public static readonly object O = new System.Object ();
233 > public static void Main () {}
240 * Merge test 89 and test-34
244 Primary-expression, as it has now been split into
245 non-array-creation-expression and array-creation-expression.
249 The information when registering a method in InternalParameters
250 is duplicated, you can always get the types from the InternalParameters
252 * Emit modreq for volatiles
254 Handle modreq from public apis.
256 * Emit `pinned' for pinned local variables.
258 Both `modreq' and pinned will require special hacks in the compiler.
260 * Make sure that we are pinning the right variable
262 * Merge tree.cs, rootcontext.cs
267 * User Defined Conversions is doing way too many calls to do union sets that are not needed
269 * Add test case for destructors
271 * Places that use `Ldelema' are basically places where I will be
272 initializing a value type. I could apply an optimization to
273 disable the implicit local temporary from being created (by using
276 * Dropping TypeContainer as an argument to EmitContext
278 My theory is that I can get rid of the TypeBuilder completely from
279 the EmitContext, and have typecasts where it is used (from
280 DeclSpace to where it matters).
282 The only pending problem is that the code that implements Aliases
283 is on TypeContainer, and probably should go in DeclSpace.
285 * Use of local temporary in UnaryMutator
287 We should get rid of the Localtemporary there for some cases
289 This turns out to be very complex, at least for the post-version,
294 To produce optimal code, it is necessary for UnaryMutator to know
295 that it is being assigned to a variable (the way the stack is laid
296 out using dup requires the store to happen inside UnaryMutator).
300 Do we really need to instanciate this variable all the time?
302 It could be static for all we care, and just use it for making
303 sure that there are no recursive invocations on it.
307 Write tests for the various reference conversions. We have
308 test for all the numeric conversions.
312 In Indexers and Properties, probably support an EmitWithDup
313 That emits the code to call Get and then leaves a this pointer
314 in the stack, so that later a Store can be emitted using that
315 this pointer (consider Property++ or Indexer++)
317 * Optimizations: variable allocation.
319 When local variables of a type are required, we should request
320 the variable and later release it when we are done, so that
321 the same local variable slot can be reused later on.
323 * Add a cache for the various GetArrayMethod operations.
325 * TypeManager.FindMembers:
327 Instead of having hundreds of builder_to_blah hash table, have
328 a single one that maps a TypeBuilder `t' to a set of classes
329 that implement an interface that supports FindMembers.
331 * MakeUnionSet Callers
333 If the types are the same, there is no need to compute the unionset,
334 we can just use the list from one of the types.
336 * Factor the lookup code for class declarations an interfaces
337 (interface.cs:GetInterfaceByName)
342 * Use of lexer.Location in the parser
346 TOKEN nt TERMINAL nt TERMINAL nt3 {
347 $$ = new Blah ($2, $4, $6, lexer.Location);
350 This is bad, because the lexer.Location is for the last item in `nt3'
352 We need to change that to use this pattern:
354 TOKEN { oob_stack.Push (lexer.Location) } nt TERMINAL nt TERMINAL nt3 {
355 $$ = new Blah ($3, $5, $7, (Location) oob_stack.Pop ());
358 Notice how numbering of the arguments changes as the
359 { oob_stack.Push (lexer.Location) } takes a "slot" in the productions.
361 * local_variable_declaration
363 Not sure that this grammar is correct, we might have to
364 resolve this during semantic analysis.