Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

disjoint closure environments

Aperta
#3 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
25/100
Tipo di issue
Refactoring
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
javascript

Direzione di ricerca

No files or tests are named. Start by locating closure-environment construction and variable-capture handling in the compiler/runtime, then compare the disjoint and shared-variable examples in this issue. Done requires a justified strategy for splitting environments, including its indirection and allocation costs.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

the following function:

function foo() {
  var a = [1,2,3,4];
  var b = 1;
  var c = 2;

  var new_a = a.map (function (el) { return el * b; }

  return function () {
    return c;
  }
}

will create a single closure environment holding both b (closed over by the function passed to map) and c (closed over by the returned function.)

In this totally disjoint case, ejs could split the closure environments, but I need to investigate if the overhead of splitting the closure makes sense for small environments (I'm guessing no for this particular case, particularly since the closed over variables are never set to anything other than primitives..)

Also, what happens if the sets are not totally disjoint? Take the following:

function foo() {
  var a = [1,2,3,4];
  var b = 1;
  var c = 2;
  var d = 4;

  var new_a = a.map (function (el) { return el * b + d; }

  return function () {
    return c + d;
  }
}

so now both functions close over d as well.

we could make 3 environments in this case;

env_0 = { d: 4 }
env_1 = { env: env_0, b: 1 }
env_2 = { env: env_0, c: 2 }

accesses to d get replaced with something different from within each function:

  1. env_1.env.d in the function passed to map
  2. env_2.env.d in the returned function.

This also has a cost in the increased indirection to get to the d binding, so need some heuristic based on the number of accesses to d to determine if we should just create 1 environment.

Lingua principale
JavaScript
Stelle
430
Fork
20
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di toshok/echojs

Tutte le issue di toshok/echojs

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.