Subj : Re: [Rhino] what is better for includes? To : Mike C. From : Igor Bukanov Date : Sun May 16 2004 11:27 am Mike C. wrote: > For using JS in a servlet environment, I translate the page into a > JavaScript only file, then I compile it with Rhino into a bytecode .class > file. > For include files, I can either > - compile each include into a separate class file, then execute the script > in the same scope as the main page > - make a big .js file for each main page, with all include files > concatenated, then compile the main page only into bytecode. > Question is, do I have any chance to get better compile-time optimizations > if I concatenate all include files to the main script? Otherwise I would use > the first solution, since the translation is simpler for it. With one big file you may hit a limitation of .class file format where the method size is restricted to 64K of bytecode. Since in Rhino all code to initialize functions declared in the script is generated as one JVM method, the 64K limit is hit when there is arround 2000 top level functions. You may also hit this limit if your script contains a lot of object and array literals since the generated code to initialize them is pretty fat. CVS tip of Rhino improves that somewhat but still the limit can be reached quickly. But if 64K is not a problem the .class file generated for the monolithic script is faster to load since JVM does not need to lookup duplicated strings and various constants are shared. In addition if your scripts contain cross calls then with the optimization level set to 1 or higher Rhino will generate faster code for these calls. Regards, Igor .