# Maximum size of a method in Processing

**URL:** <https://discourse.processing.org/t/maximum-size-of-a-method-in-processing/17136>\
**Category:** Development\
**Created:** [January 17, 2020, 9:47am UTC](https://discourse.processing.org/t/maximum-size-of-a-method-in-processing/17136 "2020-01-17T09:47:41Z")\
**Posts on this page:** 10\
**Page:** 2

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [January 18, 2020, 1:59pm UTC](https://discourse.processing.org/t/maximum-size-of-a-method-in-processing/17136/21 "2020-01-18T13:59:12Z")

</div>

> [@Thomas](#):
>
> I have different nodes, which all have a certain temperature  
> …  
> I calculate these temperatures every timestep in Processing by calling a function.

In a better world you have a csv file with temperatures (or incoming data?) of all nodes

```auto
33.5
32.4
33.9
...

```

and load the csv (you get an array a1) and then have one function (A) that for loops over the data.

> I calculate these temperatures every timestep in Processing by calling a function.

In the for loop you would call a 2nd short function (B) to calculate the temperature just for one node. Then store this back into a 2nd array a2.

Chrisir

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [January 18, 2020, 3:34pm UTC](https://discourse.processing.org/t/maximum-size-of-a-method-in-processing/17136/22 "2020-01-18T15:34:26Z")

</div>

Are the formulae you get from Matlab set in stone and the only difference being the input data?

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [January 18, 2020, 9:07pm UTC](https://discourse.processing.org/t/maximum-size-of-a-method-in-processing/17136/23 "2020-01-18T21:07:50Z")

</div>

> [@Thomas](#):
>
> Why would you use `static final` when initializing floats?

* * *

This is what Processing’s reference says about Java’s keyword `static`:

> **[static / Reference](https://processing.org/reference/static.html)**
>
> Keyword used to define a variable as a "class variable" and a method as a "class method." When a variable is declared with the static keyword, all instances of that class share the same variabl…

When a field is declared w/ that keyword, it means Java creates it once only, no matter how many times we instantiate its `class`.

Thus it is said such a field is shareable, b/c its value is the same across all instances of its `class`.

But the coolest thing about `static` is that any member of a `class` declared w/ that can be accessed directly w/o needing to create an instance of its `class` 1st!

However, considering a Processing sketch is never instantiated more than once (unless we hackishly force our hand to do it), declaring its fields and methods w/ `static` is moot; and we can safely remove such declaration if we prefer so.

I only do it as a way to document that such PApplet members (apart from nested classes) are stateless rather than any practical effect on the code.

* * *

This is what Processing’s reference says about Java’s keyword `final`:

> **[final / Reference](https://processing.org/reference/final.html)**
>
> Keyword used to state that a value, class, or method can't be changed. If the final keyword is used to define a variable, the variable can't be changed within the program. When used to define a…

When used on fields, local variables & parameters, it permanently seals the 1st value assigned to them.

But in this particular sketch of yours, `final` is also crucial to shorten the memory used by method **calculateT1()**. 😓

If we remove the 2nd keyword `final` declaration from where the **pow()** `float` fields are, the sketch still compiles & runs fine. 😌

However, if we dare removing the 1st `final` declaration from the original `float` fields, we’ve got the compilation error back: 😨

> The code of method calculateT1(float, float) is exceeding the 65535 bytes limit.

Seems like the 2nd batch of `float` fields isn’t used as much as the 1st 1 to the point of exceeding the limit. 😛

BtW, I always try to stick the keyword `final` everywhere as long as I can get away w/ it. 😈

Actually, when I had already replaced about 4 or 5 **pow()** batch calls w/ `final` constants, the sketch was already able to compile & run! 😮

I’ve continued to replace all **pow()** calls w/ `final float` constants just for completeness’ sake. 😫

In short, both declaring the original `float` fields w/ `final` and replacing some of the batches of **pow()** calls w/ pre-calculated fields were the bare requirements in order to compile & run **calculateT1()**. 🧐

But still, what kinda trick the `final` keyword does to the `float` fields which was crucial to shorten method **calculateT1()** barely enough? 🤔

That trick is made outta “Constant Expressions”: 🧙  
[Docs.Oracle.com/javase/specs/jls/se11/html/jls-15.html#jls-15.28](http://Docs.Oracle.com/javase/specs/jls/se11/html/jls-15.html#jls-15.28)

It kicks in everytime we assign a primitive or literal String to a `final` field, turning them into a “known compile time constant”! 🤓

That makes the compiler replace all occurrences of such fields w/ their actual literal value across the compiled bytecode! 🥳

That’s a rarity; b/c Java isn’t used to optimize code on compile time, but leaving them on run time. 🏃‍♂️

As an example, this `final` field would be a “known compile time constant”: 👌  
`final float F1s = 1;`.

However this 1 wouldn’t due to method call, which isn’t a constant expression, although it’s `final`: 👎  
`final float F1s = cos(0);`.

More on “known compile time constant” explanation stuff here: 🤠  
[CodeRanch.com/t/612483/java/compile-time-constant](http://CodeRanch.com/t/612483/java/compile-time-constant)

* * *

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [January 18, 2020, 11:29pm UTC](https://discourse.processing.org/t/maximum-size-of-a-method-in-processing/17136/24 "2020-01-18T23:29:45Z")

</div>

> [@Thomas](#):
>
> How did you replace all the powers? Ctrl-F and then replace with something else?

More precisely I’ve used CTRL+H inside Notepad2-mod:  
[XhmikosR.GitHub.io/notepad2-mod](http://XhmikosR.GitHub.io/notepad2-mod)

I did the same to split each expression into its own line.

For that, I’ve relied on the option “Transform backslashes” so I could replace all + & - occurrences this way: &nbsp;+\n & &nbsp;-\n.

Also used CTRL+B over an open parenthesis in order to find its matching closing 1.

On a side note, JS got no problems running even your original “test.pde”.

You can see it by yourself using the “Processing Helper” tool from this site below:  
[ProcessingJs.org/tools/processing-helper.html](http://ProcessingJs.org/tools/processing-helper.html)

Just copy & paste your or my version there and click at the “Run” button.

It’s gonna print out: 253.0466351680599

---

<div class="post-metadata">

**Author:** ![Thomas](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/thomas/32/7236_2.png) [@Thomas](https://discourse.processing.org/u/Thomas)\
**Post date:** [January 20, 2020, 9:58am UTC](https://discourse.processing.org/t/maximum-size-of-a-method-in-processing/17136/25 "2020-01-20T09:58:25Z")

</div>

Thanks, but how can I use multiple .pde files in that mode ([ProcessingJs.org/tools/processing-helper.html](http://processingjs.org/tools/processing-helper.html))? Also, I tried installing JavaScript mode, but unfortunately not succeeded in doing so.

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [January 20, 2020, 10:10am UTC](https://discourse.processing.org/t/maximum-size-of-a-method-in-processing/17136/26 "2020-01-20T10:10:34Z")

</div>

> [@Thomas](#):
>
> , but how can I use multiple .pde files in that mode

Take a look inside the “.html” files from these 2 sketches below:

> <https://github.com/GoSubRoutine/Grumbo/tree/master/Grumbo_Adventure_OOP>
>
> //github.com/GoSubRoutine/Grumbo/tree/master/Grumbo\_Adventure\_OOP

[https://github.com/GoSubRoutine/Ball-in-the-Chamber/tree/master/pjs-java](https://github.com/GoSubRoutine/Ball-in-the-Chamber/tree/master/pjs-java)

> [@Thomas](#):
>
> , I tried installing JavaScript mode,

Again, the whole Pjs library link is loaded using an “.html” file:

> <https://github.com/GoSubRoutine/Grumbo/blob/master/Grumbo_Adventure_OOP/index.html>

[https://github.com/GoSubRoutine/Ball-in-the-Chamber/blob/master/pjs-java/index.html](https://github.com/GoSubRoutine/Ball-in-the-Chamber/blob/master/pjs-java/index.html)

There’s no actual need to “install” anything:  
[GoSubRoutine.GitHub.io/Grumbo/Grumbo\_Adventure\_OOP](http://GoSubRoutine.GitHub.io/Grumbo/Grumbo_Adventure_OOP)  
[GoSubRoutine.GitHub.io/Ball-in-the-Chamber/pjs-java/](http://GoSubRoutine.GitHub.io/Ball-in-the-Chamber/pjs-java/)

---

<div class="post-metadata">

**Author:** ![Thomas](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/thomas/32/7236_2.png) [@Thomas](https://discourse.processing.org/u/Thomas)\
**Post date:** [January 20, 2020, 8:35pm UTC](https://discourse.processing.org/t/maximum-size-of-a-method-in-processing/17136/27 "2020-01-20T20:35:16Z")

</div>

@GoToLoop , thank you for your patience with me 😁 If I open the .html file in Google Chrome I just see a white screen. Even if I download your files of Grumbo, it doesn’t work. Sorry, I’m new to all of this.

Edit: I tested with these files and I don’t see the cancas, only the header and paragraph:

**index.html**

```auto
<!DOCTYPE html>
<html>
<body>

<h1>My First Heading</h1>
<p>My first paragraph.</p>

</body>
</html>

<script defer src=https://raw.githubusercontent.com/processing-js/processing-js/v1.4.8/processing.js></script>

<canvas data-processing-sources=
  "test.pde">
</canvas>

```

**test.pde**

```auto
void setup(){
    size(800,400);
}

void draw(){
    background(0);
    stroke(200);
    fill(255,0,0);
    rect(100,100,100,100);
}

```

I only have to open the index.html in Google Chrome, right?

Thanks again,  
Thomas

---

<div class="post-metadata">

**Author:** ![hamoid](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hamoid/32/58_2.png) [@hamoid](https://discourse.processing.org/u/hamoid)\
**Post date:** [January 20, 2020, 10:38pm UTC](https://discourse.processing.org/t/maximum-size-of-a-method-in-processing/17136/28 "2020-01-20T22:38:13Z")

</div>

I haven’t followed the whole discussion but the html doesn’t look right: I think the script and the canvas should be between the `</p>` and the `</body`.

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [January 21, 2020, 1:43am UTC](https://discourse.processing.org/t/maximum-size-of-a-method-in-processing/17136/29 "2020-01-21T01:43:42Z")

</div>

> [@Thomas](#):
>
> If I open the .html file in Google Chrome I just see a white screen.

> [@Embedding .pde to html does not work/ .pde to p5.js](https://discourse.processing.org/t/embedding-pde-to-html-does-not-work-pde-to-p5-js/16181/6):
>
> The problem is that browsers block loadings from “file://” scheme. You’re gonna need some local server in order to run “.js” scripts as “http://” scheme instead. Alternatively, you can install Firefox: Once installed, go to its about:config page. Then at the search box there, type in privacy.file\_unique\_origin, and toggle it to false. Now you can run most sketches from there via the “file://” scheme.

Another workaround: [Chrome-allow-file-access-from-file.com](http://Chrome-allow-file-access-from-file.com)

A more complete solution:

> **[GitHub - kzahel/web-server-chrome: An HTTP Web Server for Chrome...](https://github.com/kzahel/web-server-chrome)**
>
> An HTTP Web Server for Chrome (chrome.sockets API) - GitHub - kzahel/web-server-chrome: An HTTP Web Server for Chrome (chrome.sockets API)

More solutions: [Local server · processing/p5.js Wiki · GitHub](http://GitHub.com/processing/p5.js/wiki/Local-server)

---

<div class="post-metadata">

**Author:** ![jsgro](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@jsgro](https://discourse.processing.org/u/jsgro)\
**Post date:** [January 24, 2020, 2:11am UTC](https://discourse.processing.org/t/maximum-size-of-a-method-in-processing/17136/30 "2020-01-24T02:11:12Z")

</div>

If these are variables maybe the best work around is to use a statistical method like GAM or an ordination method like a CCA and reduce your data to only the important variables.

[Previous page](https://discourse.processing.org/t/maximum-size-of-a-method-in-processing/17136.md?page=1)
