News for hackers. Stuff that matters.
Re:The Principles of Versioning in Go by sansnomme on Tuesday December 03, 2019 @03:30PM (#21696363)
I think calling it a SAT solver is appropriate here. A lot of package managers were "organically grown" i.e. they were created in response to a problem that arose. Not much thought was given to the underlying problem and in the long term users suffer with e.g. dependencies taking forever to install and strange deadlocks. Recognizing it as a SAT problem from the start means we can easily throw Z3 or similar at it instead of manually adding heuristics everytime a user files a GitHub issue. (See Bundler and other pre-2018/2017 package management tools for example) Also, it's not always a SAT problem. For npm, Java Classloaders it's just tree traversal because conflicting sub dependencies of a dependency can co-exist.

That said, the Go's team (and to a lesser extent Python's too) dropped the ball here. None of the challenges of dependency management was unknown or unsolved. Anyone who has used e.g. Maven should be more than familiar. (A 11 section blog post is indeed nice though, good for onboarding new programmers I suppose) If developer experience was considered a first class priority, this could have been solved from day 0.

(My personal favorite is NPM since conflicting dependencies can co-exist at the expense of greater disk usage, but memory is cheap these days. No one with an electron app on their desktop has any right to complain about the memory usage of plain text source code.)

Re:The Principles of Versioning in Go by pcwalton on Tuesday December 03, 2019 @03:37PM (#21696436)
See, that's the reason why calling it a SAT solver makes the problem sound scarier than it is. Using Z3--or even MiniSAT--is massive overkill. The naive exponential algorithm is fine, and it leads to more maintainable and understandable code. Rust's build performance has nothing to do with dependency solving. I've never heard of a package manager in which core dependency solving was a speed problem; dep was slow because of I/O, not SAT solving.
Re:The Principles of Versioning in Go by munificent on Tuesday December 03, 2019 @04:42PM (#21697030)
> I've never heard of a package manager in which core dependency solving was a speed problem

Natalie Weizenbaum and I wrote the package manager for Dart. My naïve backtracking version solver was fine ~98% of the time. 2% of the time it was catastrophically, exponentially slow. Natalie wrote a much better one to solve exactly that:

https://medium.com/@nex3/pubgrub-2fb6470504f

Re:The Principles of Versioning in Go by littlestymaar on Wednesday December 04, 2019 @06:40AM (#21701345)
If I correctly understood the post you linked, it looks like there is a big difference between Rust and Dart when it comes to dependency management: Rust allows for different major version of a crate to appear in the dependency tree, while it seems (from the first example given by the post) that Dart doesn't. That difference would dramatically change the difficulty of dependency resolution between the two languages, because there will be many more unsatisfiable cases in Dart than in Rust, leading to much more work to find a working set. (In the given example, cargo would just pick icon:1.0.0 and menu:1.5.0-> dropdown:2.3.0->icon:2.0.0, and call it a day).

The exponential search issue could arise if people used explicit upper bound on crate minor of patch versions, but since the number of crate doing that is few far between, there's little change to encounter such a degenerated exponential case in practice.

Re:The Principles of Versioning in Go by pcwalton on Tuesday December 03, 2019 @05:16PM (#21697405)
That hasn't been our experience with Cargo. It's always been fast.

As a colleague of mine pointed out, the lockfile makes the solving a non-issue in practice anyway.

Re:The Principles of Versioning in Go by steveklabnik on Tuesday December 03, 2019 @05:32PM (#21697555)
To be clear, Cargo doesn't actually use a SAT solver, it's depth-first search with some heuristics. Without knowing more about how Dart's solver worked, it's hard to directly compare. https://github.com/rust-lang/cargo/blob/368333c2070279347723...
Re:The Principles of Versioning in Go by Groxx on Tuesday December 03, 2019 @03:41PM (#21696479)
I/O + the absurd lengths you need to go to to (mostly) safely use Git as an external binary + no package repository to globally cache things like package names and versions. yea. "SAT solving" was an incredibly tiny amount of the runtime, like you'd expect for a CPU-bound algorithm.

It's a straw man that keeps getting dragged out, but anyone who has used and understood this kind of dependency manager knows it's meaningless. You can definitely argue about its impact on community behavior, but it functions just fine, handles a ton of real-world issues reasonably, and it's nowhere near slow enough to care about.

Re:The Principles of Versioning in Go by ainar-g on Tuesday December 03, 2019 @03:46PM (#21696526)
> The naive exponential algorithm is fine (…)

Define “fine”. In my experience, Go with modules[1] solves a project's dependencies exponentially more quickly than dep. And that is especially noticeable on big projects with three or more dozens of dependencies. I don't mean any disrespect to the people behind dep, and the whole debacle was a massive miscommunication disaster, but go mod is just quicker.

[1] While we're at it, I'm still low-key mad that the Go authors called modules packages and packages modules. Gah!

Re:The Principles of Versioning in Go by earthboundkid on Tuesday December 03, 2019 @10:30PM (#21699349)
I complained about the term “modules” for the bigger code unit in Reddit, but RSC said they were both vague so it didn’t matter. I do still think it should have been “bundles” or something implying “bigger than a package” instead of “module”.
Re:The Principles of Versioning in Go by pcwalton on Tuesday December 03, 2019 @03:51PM (#21696568)
Again, that's because of I/O. The CPU bound part of the algorithm is very fast, as Cargo demonstrates.
Re:The Principles of Versioning in Go by ainar-g on Tuesday December 03, 2019 @04:01PM (#21696665)
I don't get it. The number of dependencies is constant. Which means that both of them need to make approximately the same amount of network requests. Where does the I/O difference come from then?

Also, since you've mentioned Cargo. Its slowness actually used to be one of the main pain points about which the Rust people at one of the companies I've worked for in the past complained a lot during the water cooler discussions. Granted, that was a couple of years ago, and Cargo has probably made progress since then.

Re:The Principles of Versioning in Go by pcwalton on Tuesday December 03, 2019 @04:03PM (#21696683)
As I recall, dep had to parse Go code over and over during the dependency resolution process instead of caching it.

And any cargo slowness is likely the fault of rustc or I/O. It's received a lot of profiling work and the core dependency solver has never been a performance issue to my knowledge.

Re:The Principles of Versioning in Go by steveklabnik on Tuesday December 03, 2019 @04:22PM (#21696861)
It would seem this is correct. From the docs: https://github.com/golang/dep/blob/master/docs/FAQ.md#why-is...

There are two things that really slow dep down. One is unavoidable; for the other, we have a plan.

The unavoidable part is the initial clone. ... Fortunately, this is just an initial clone - pay it once, and you're done.

The other part is the work of retrieving information about dependencies. There are three parts to this:

* Getting an up-to-date list of versions from the upstream source

* Reading the Gopkg.toml for a particular version out of the local cache

* Parsing the tree of packages for import statements at a particular version The first requires one or more network calls; the second two usually mean something like a git checkout, and the third is a filesystem walk, plus loading and parsing .go files. All of these are expensive operations.

----------------

For context, in comparison, Cargo has the same #1 problem. But for #2, the information on all dependencies is stored in the index itself; this means that Cargo can figure out what dependencies you need without any network calls at all, let alone downloading, git checkout, and filesystem walk.

I do not know how go mod compares, off the top of my head.

Re:The Principles of Versioning in Go by sansnomme on Tuesday December 03, 2019 @04:01PM (#21696664)
The trend these days is tiny packages (similar to PaaS turning into Function-as-a-service), very fine grained libraries like Leftpad. The ultimate realisation of HN's favorite mantra "worship the Unix Philosophy". Expect the number of dependencies to only increase.
Re:The Principles of Versioning in Go by kortex on Tuesday December 03, 2019 @10:33PM (#21699366)
Except you have things like `sed` and `cut` and `cat`, not `lpd` which solely exists to add leftwise filler characters. Ergonomics of those tools nonwithstanding, they are simple but they aren't TOO simple.

Left-pad is IMHO "too simple". Packages on the median should be in a 1-2 pizza team effort with some ongoing maintenance, even if only a few pizzas a year. Left-pad is like, 2 pizzas and a weekend.

(were it not for string.prototype methods) a viable package would be something on the order of Python's str.format(). Can left pad and right pad!

Re:The Principles of Versioning in Go by samatman on Tuesday December 03, 2019 @11:58PM (#21699719)
Unix notoriously has the command `yes`, which provides an infinite loop of `y\n`.

Don't have a strong opinion on whether left-pad should exist or not (or indeed, if server-side Javascript should exist or not), but simpler than left-pad, is yes? yes.

Re:The Principles of Versioning in Go by iudqnolq on Wednesday December 04, 2019 @11:39PM (#21710033)
Having a basic building block that enables a lot is different from making every tiny problem it's own package. Yes is a exception, certainly, but it doesn't disprove the rule.
Re:The Principles of Versioning in Go by sacado2 on Wednesday December 04, 2019 @09:13AM (#21702274)
> dep was slow because of I/O, not SAT solving.

Actually dep tended to produce suboptimal solutions, meaning in some cases it downloaded too many packages to solve dependencies. And that meant more I/O operations than needed. Plugging a full-blown SAT solver would have solved this issue.

Re:The Principles of Versioning in Go by sansnomme on Tuesday December 03, 2019 @03:46PM (#21696525)
Ask the Python pipenv people. Take a look at their GitHub issues.

https://github.com/pypa/pipenv/issues

Perhaps they need to "rewrite it in Rust" /s

Their competitor's isn't much better either when it comes to dependency resolution related bugs.

https://github.com/sdispater/poetry/issues

Re:The Principles of Versioning in Go by steveklabnik on Tuesday December 03, 2019 @04:29PM (#21696928)
https://poetry.eustace.io/docs/faq/#why-is-the-dependency-re...

This is due to the fact that not all libraries on PyPI have properly declared their metadata and, as such, they are not available via the PyPI JSON API. At this point, Poetry has no choice but downloading the packages and inspect them to get the necessary information. This is an expensive operation, both in bandwidth and time, which is why it seems this is a long process.

https://github.com/pypa/pipenv/issues/2284#issuecomment-3952... (from 2018, may be outdated)

we compute a resolution graph that attempts to satisfy all of the dependencies you specify, before we build your environment. That means we have to start downloading, comparing, and often times even building packages to determine what your environment should ultimately look like, all before we've even begun the actual process of installing it (there are a lot of blog posts on why this is the case in python so I won't go into it more here).

------------------

As I stated in another comment on this thread, Cargo has to do none of this. This stuff is the source of things being slow, not the actual "Okay I have all the versions and constraints, what's the answer" bit.

Re:The Principles of Versioning in Go by sansnomme on Tuesday December 03, 2019 @04:46PM (#21697089)
Are there any plans to increase the amount of metadata on e.g PyPy?
Re:The Principles of Versioning in Go by steveklabnik on Tuesday December 03, 2019 @04:48PM (#21697123)
I have no idea, I'm not involved in Python in any way.
Re:The Principles of Versioning in Go by mntmoss on Tuesday December 03, 2019 @05:03PM (#21697288)
I think the appropriate way to view this is not just as that this domain needs "SAT" (which enforces standardized algorithms as "the solution") so much as it describes an urgent need to popularize the concept of constraint satisfaction and optimization problems as a domain of coding that programmers actually deal with regularly and informally. Being able to sort, search and rank is the first step to having a backtracking solver, a technique that is very powerful and generalizable(albeit slow). But how many CS programs teach you to write solvers?

Our education methods could do a lot more to draw this technique into its applications. For example, in game programming, satisfaction tends to come up rather abruptly when talking about physics solvers; not because it's only needed then, but because the jargon was appropriated from academic simulation papers, and it comes as part of a sudden bomb of math concepts, making it look more intimidating than it is. Non-realistic physics are just called "collision code", handwaved away and not given a great deal of formal attention, even though they are performing the work of solvers too, just usually with a mix of linear programming and local search. As such, a lot of new game programmers get stuck on collision problems and concurrency bugs that result from poorly constrained solutions, because they don't have the conceptual tools surfaced to reason about it with confidence.

Likewise there are plenty of CRUD-style apps where a solver is a helpful building block for creating views and filters, but it's not approached as one, so you just get a buggy feature.

Re:The Principles of Versioning in Go by mfer on Tuesday December 03, 2019 @03:33PM (#21696400)
> A lot of package managers were "organically grown"

Many of the package managers we have now are thought out. Some replaced existing ones while others were crafted by people who had worked on dependency management in the past. Cargo and Composer are two examples of this.