0

I need to populate ~20k built-in function and constants from an CHM file into a List. First I tried to serialize a list of them, but deserialization takes 1500ms (too long for a quick code-completion, even at the first hit).

Tried code generation using StringTemplate, which generates valid code. But it won't compile because "initEnums() method exceeded size limit of 65536". (And my Eclipse dies soon after)

The generated method looks like this:

public XModelField[] initEnums() {
    return new XModelField[] {
        new XModelField("aName", "aType", ...),
        ...
        // About 4'000 more entries
    };
}

If this limit is constrained only to source code, I could use another library to generate the class file directly (maybe CodeModel). I'd like to keep my code, if possible without rewriting the output generator from scratch again. Any suggestions?

  • what about deserialising in advance (and/or aggressive caching)? – John Dvorak Mar 26 '13 at 19:02
  • 1
    this constraint is a constraint of the class files. The source code parser couldn't care less.about arbitrary limits. – John Dvorak Mar 26 '13 at 19:11
  • @jan Already aggressively enhancing startup and performance. Also I don't want reverse engineering hobbyists copying my data easily; the class dependencies should set them behind for a moment. I assume CodeModel does not have any limit of this kind on methods, right? – Matej 'Yin' Gagyi Mar 27 '13 at 09:15

1 Answers1

1

I think you should reconsider your strategy. Model your data structures and methods accordingly and you don't have to generate code. Instead to generate the Java code for 4000 constants, store your data in a file or database and write a short method to read that data in at initialization time to fill a list with your data objects.

Generating code is a powerfull tool but you should utilize it carefully. I don't see it is even necessary for your use case, but if you think it is, then you can try to minimize the portion of code to generate to an absolute minimum to keep things simple. Often you can extract a lot of generic code to an abstract super class so that you only has to generate the code for some methods in subclasses. And generating code for 4000 constants is really unnecessary. Keep data as data and operate on your data dynamically.

vanje
  • 10,180
  • 2
  • 31
  • 47
  • I used ASM framework, but very similar limitation constrains class files. The only error message I've got was simply "Method body too large". – Matej 'Yin' Gagyi Apr 04 '13 at 15:21
  • @Matej'Yin'Gagyi That is the method body of the special class initialization method ``, which has to initialize all the class' constants. – Paŭlo Ebermann Apr 11 '13 at 20:11
  • @PauloEbermann I am calling initialization each method from clinit. It doe not matter how you structure the calls. If a method is too big, it's too big. – Matej 'Yin' Gagyi Apr 13 '13 at 16:56