question

Brandon Peterson avatar image
10 Likes"
Brandon Peterson asked Brandon Peterson commented

Do you have a faster more simple way to access data from Global Tables - Challenge Question

Recently I built a model that was simulating up to 1.35 million units per day and would run for up to 40 days. Obviously this is a lot of events and the model took longer than one of my typical models. When looking for ways to speed up the simulation I noticed that I was looking up and setting data in global tables multiple times for each of the 1.35 million units... OUCH!!

In the past I have used global macros to reference global tables when I use any of the global table commands. I did this for two reasons: First, I thought that it was faster than using strings (eventhough I did not have any empirical results to back me up). Second, it made the model a little easier to adjust when changes were made later in the life of the project. This model was no exception and I was using global macros to reference the tables.

So, my question is: Do you have a way of referencing the global tables that is faster and preferably as simple and robust as using global macros?

I plan on building a sample model to run some experiments of my own to answer this question. However, I believe that all of you out there are more than capable of having a better solution than myself. So, this is a "Challenge Question" in that I would like to challenge you to beat my answer and any others posted to this question. Over time I hope that we will all benefit by seeing all of the different methods/ways that this can be done.

Thanks and good luck!

Brandon

FlexSim 16.0.1
global tableglobal variablesrun timeglobal macroschallenge question
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

·
Brandon Peterson avatar image
10 Likes"
Brandon Peterson answered Brandon Peterson commented

All,

To answer the question and find a faster way to execute calls to the global tables I created the attached sample model. The model uses the FlexScript Code Profiler to determine the amount of time that it takes to call the gettablenum() command. The model was setup as follows:

  • 10 Global tables were added to the model using the default table names
  • Each global table was sized to 10x10
  • All of the cells toggled as numeric data and their values set to 0
  • Global macros were created to reference the rank of each table
  • Global variables were created to reference the table node
  • User commands were created to call gettablenum() from the 1st, 5th, and 10th tables with the table being passed in as a:
    • String – table name
    • Number – table rank
    • Macro – table rank with a global macro
    • Tree Node – table reference with a global variable

I then opened up a script window and entered some code to execute all 12 user commands a specified number of times.

In total all 12 commands were executed 44 million times in 8 executions of the script window code. I have attached an Excel file that contains all of the results along with some analysis/comparison calculations.

Here is a short summary of the results:

  • Tree node reference from a global variable was the fastest method that I tested. It was approximately 3X faster than using a string with the table name.
    • Tree Node – Fastest at 33% of String
    • Macro – Second Fastest at 64.9% of String
    • Number – Third Fastest at 66% of String (Only slightly slower than Macro)
    • String - Slowest
  • The rank of the global table has a slight impact on the speed depending on the method used to reference the global table
    • String – (1,5,10) - lower ranked tables were faster
    • Number – (5,10,1) - the middle table was fastest, followed by the last with the first being slowest
    • Macro – (10,5,1) – lower ranked tables were slower
    • Tree Node – (10,5,1) – lower ranked tables were slower

In the past I would almost exclusively us global macros to define the ranks of my tables and then use the macros in my code. My conclusion from this experiment is that I have been using the wrong (i.e. slower) method. I will be switching over to using global variables to reference my global tables for all of my future models.

I hope that this was as helpful to you as it was to me. Even more, I hope that one of you will have an even faster and more simple method for me to use!

Brandon


· 4
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

anthony.johnson avatar image anthony.johnson ♦♦ commented ·

Some thoughts:

1. I wonder if there is much of a difference between using a bundle table vs. a standard tree-based table.

2. I wonder if there are mechanisms by which you could decrease the overall load by simply decreasing the number of times you are referencing the table. Are you searching/prioritizing/filtering the table? This might be improved by using the query() command to sort/filter stuff at the beginning of the model, and then maybe cache data off into arrays or using lists (unfortunately arrays can only be stored with the setlabel() command right now, but that will hopefully change soon).

5 Likes 5 ·
Brandon Peterson avatar image Brandon Peterson ♦ anthony.johnson ♦♦ commented ·

I updated the model to include a method that uses bundles and functions for setting a value. I have attached the model and excel file to this response.

What to take away from the new results:

  • The bundle method was only slightly faster than using tree node references in global variables
    • Not worth the extra work in my opinion
  • When setting a value both the number and macro methods are slower than the string method (table names).
    • This was very surprising
    • Still way slower than the tree node and bundle methods
  • For both the number and macro methods the get commands are around 40% faster than the set commands
    • only about 6% for the string, tree node, and bundle methods

I hope that these updated results are helpful,

Brandon

3 Likes 3 ·
Brandon Peterson avatar image Brandon Peterson ♦ Brandon Peterson ♦ commented ·

Phil and I looked into the speed difference between get and set using the number and macro methods. Turns out, there was a difference between the two commands in the way that they found the table. In future releases both commands will use the faster method.

At that time the string method will be the slowest method for set as it currently is for get.

Thanks Phil!

@phil.bobo

3 Likes 3 ·
Brandon Peterson avatar image Brandon Peterson ♦ anthony.johnson ♦♦ commented ·

In the original model that spawned the question I did implement some of your suggestions by caching a lot of the table data to labels prior to the loops that were executed millions of times. The table calls that could not be cached to labels were the ones where data was being written to and ready by different items/tokens and so could not be stored in the label of a single item/token.

I did not try using bundles though. That would have been a good experiment.

2 Likes 2 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.