Skip to content

repy.py / safe.py memory efficiency issues #99

@aaaaalbert

Description

@aaaaalbert

It's not really evident on platforms with more than 128 MB of memory, but a few things in repy.py and safe.py are less than efficient when dealing with memory, at least transiently. (I will use this issue to talk about these problems overall, and probably add specific sub-issues for the different parts that are affected).

The startup process of a Repy sandbox works like this. (When started through the nodemanager, the callargs will differ a little, but the process is unchanged.)

  • Repy initializes, then forks resource manager and the actual sandbox. --- Better fork early while the process isn't that large yet, then init sandbox in child only. (See also nmmain self-daemonizing is memory inefficient nodemanager#117).
  • safe.py which is called by the sandbox serves three mostly separate purposes:
    • Static code analysis (catches print, illegal var names)
    • Actual runtime execution
    • SafeDict
  • safe.py Popen()s another process for safe_check.py which in turn imports safe, of which it only needs the static-checking part.
  • safe.py's _check_node is tail recursive, but Python does no elimination, and so the call stack can grow large. --- Do breadth-first instead, visit children etc. of nodes later.

I'm working on these issues one by one and will report what the memory savings are for each.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions