Will memory usage change between field level and document level?

Jun 07, 2020

Copy link to clipboard

Copied

Does writing all the code in each field, or writing a document-level function and writing it, change the overall processing speed of the document?

 

Does (1) and (2) below change the overall document processing speed? For example, suppose there are about 20 fields that use the same calculation. And suppose it's a bit longer code.

 

(1) Write the same code in all fields.
(2) Write a document level function and use it.

 

Obviously, (2) is the safest and easiest way to write code.

 

Is there any difference between (1) and (2) above?  Of particular interest is how PDF JavaScript uses memory.  I've heard that generally global functions use a lot of memory, so it's better not to use too much.

I believe you read that uses of the "Global" object should be limited, because it can cause memory usage issues. This has nothing to do with functions.

 

Functions and JavaScript code in general have no greater or lessor affect on memory that depends on location. Now, if you put the same code in several different fields, this does take up more memory, but the amount is trival.

The actions the scripts perform however, can have a huge effect on memory. The JavaScript engine does not clean up unused objects quickly.  So if you write code that creates lots of new objects (variables) it can cause problems. 

TOPICS
Acrobat SDK and JavaScript, PDF forms

Views

308

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Will memory usage change between field level and document level?

Jun 07, 2020

Copy link to clipboard

Copied

Does writing all the code in each field, or writing a document-level function and writing it, change the overall processing speed of the document?

 

Does (1) and (2) below change the overall document processing speed? For example, suppose there are about 20 fields that use the same calculation. And suppose it's a bit longer code.

 

(1) Write the same code in all fields.
(2) Write a document level function and use it.

 

Obviously, (2) is the safest and easiest way to write code.

 

Is there any difference between (1) and (2) above?  Of particular interest is how PDF JavaScript uses memory.  I've heard that generally global functions use a lot of memory, so it's better not to use too much.

I believe you read that uses of the "Global" object should be limited, because it can cause memory usage issues. This has nothing to do with functions.

 

Functions and JavaScript code in general have no greater or lessor affect on memory that depends on location. Now, if you put the same code in several different fields, this does take up more memory, but the amount is trival.

The actions the scripts perform however, can have a huge effect on memory. The JavaScript engine does not clean up unused objects quickly.  So if you write code that creates lots of new objects (variables) it can cause problems. 

TOPICS
Acrobat SDK and JavaScript, PDF forms

Views

309

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jun 07, 2020 0
Jun 07, 2020

Copy link to clipboard

Copied

"I've heard that generally global functions use a lot of memory, so it's better not to use too much."

Where have you heard or read this?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 07, 2020 0
Jun 07, 2020

Copy link to clipboard

Copied

I'm sorry, but I don't remember where the page actually was. I read it on the page that describes JavaScript.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 07, 2020 0
Jun 07, 2020

Copy link to clipboard

Copied

I don't believe there's any difference at all in memory consumption, and of course not in "safety", whatever that means.

It's much better to use a doc-level script with a function that is called from the individual fields because if you need to edit the code you can just do it once and don't need to go field by field to edit it.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 07, 2020 0
Jun 08, 2020

Copy link to clipboard

Copied

Thank you very much. I was relieved to hear it.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 08, 2020 0
Jun 07, 2020

Copy link to clipboard

Copied

I believe you read that uses of the "Global" object should be limited, because it can cause memory usage issues. This has nothing to do with functions.

 

Functions and JavaScript code in general have no greater or lessor affect on memory that depends on location. Now, if you put the same code in several different fields, this does take up more memory, but the amount is trival.

The actions the scripts perform however, can have a huge effect on memory. The JavaScript engine does not clean up unused objects quickly.  So if you write code that creates lots of new objects (variables) it can cause problems. 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 07, 2020 0
Jun 08, 2020

Copy link to clipboard

Copied

Thank you very much. Your explanation was all I wanted to know. I learned a lot.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 08, 2020 0